Ask a Question related to PERL Beginners, Design and Development.
-
Nancy Clark #1
Fwd: Is it a perl Bug?
Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
Subject: Is it a perl Bug?
Date: Wed, 04 Feb 2004 12:43:56 +0200
Dear all,
I've following code :
==========
#!/usr/bin/perl
my $a = "ab:cd:ef";
my @b = split(/:/,$a);
print ("@b\n");
my @c = ('/:/', $a);
my @d = split(@c);
print ("@d\n");
===========
Whats wrong with my code?
why @b and @d give different output?
Rgds,
Tom Franklyn
------------------------------------------------------------
Jesus?? Not a God!
[url]http://www.geocities.com/abdlfth99/jesus_not_a_god.htm[/url]
---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
Nancy Clark Guest
-
Off Topic: Active Perl Native Windows / cygwin perl
I have both activestate windows native perl installed and the default cygwin perl. How can I have the cygwin shell use the windows perl rather... -
Control a non-perl image viewer from perl script
Below is a (non-finished) script that trys to run a linux viewer called eog (eye of gnome) in a script that will eventually allow me to power thru... -
Re : Installing CPAN Perl Modules with Activestate Perl 5. v5.8
Hi, In the process of trying to get perl modules installed, I downloaded over 300 Activestate specific perl modules and they work fine (of the ones... -
Effeciency question - perl scripts v's perl exe's
Max Adams wrote: The only existing Perl compiler is part of perl. Anything else is just a packager that puts a perl, required modules, and the... -
Designing Interfaces with Perl and Perl APIs
Hi, I am a long date perl programmer, and from time to time, I am having the same trouble: - To design interfaces for a self contained... -
Gary Stainburn #2
Re: Fwd: Is it a perl Bug?
On Wednesday 04 February 2004 10:48 am, nancy clark wrote:
What exactly are you wanting to happen here?> Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
> Subject: Is it a perl Bug?
> Date: Wed, 04 Feb 2004 12:43:56 +0200
>
> Dear all,
>
> I've following code :
>
> ==========
> #!/usr/bin/perl
>
> my $a = "ab:cd:ef";
> my @b = split(/:/,$a);
> print ("@b\n");
>
> my @c = ('/:/', $a);
> my @d = split(@c);
What you're actualy doing is calling
split(/ab/,'cd','ef');
which says use 'ab' as the pattern,'cd' as the expr, and 'ef' as the limit.
split obviously can't handle this and thus returns undef.
--> print ("@d\n");
> ===========
> Whats wrong with my code?
> why @b and @d give different output?
>
> Rgds,
> Tom Franklyn
> ------------------------------------------------------------
> Jesus?? Not a God!
> [url]http://www.geocities.com/abdlfth99/jesus_not_a_god.htm[/url]
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free web site building tool. Try it!
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
Gary Stainburn Guest
-
Rob Dixon #3
Re: Is it a perl Bug?
Nancy Clark wrote:
Hi Tom, Nancy.>
> Tom Franklyn <tomfranklyn@hotmail.com> wrote:From: "Tom Franklyn"
> Subject: Is it a perl Bug?
> Date: Wed, 04 Feb 2004 12:43:56 +0200
>
> Dear all,
>
> I've following code :
>
> ==========
> #!/usr/bin/perl
>
> my $a = "ab:cd:ef";
> my @b = split(/:/,$a);
> print ("@b\n");
>
> my @c = ('/:/', $a);
> my @d = split(@c);
> print ("@d\n");
> ===========
> Whats wrong with my code?
> why @b and @d give different output?
Two problems here. First of all
my @c = ('/:/', $a)
should be either
my @c = (':', $a)
or
my @c = (qr/:/, $a)
otherwise the regex would match the three characters
slash, colon, slash.
Secondly, 'split' is prototyped, so it forces its first
parameter into scalar context. Array @c has two elements
so your call
my @d = split(@c)
is equivalent to
my @d = split(2)
which will try to split $_ on the regex '2'.
Look at this code:
$_ = "ab2cd2ef";
my @c = (1, 2);
my @d = split(@c);
print ("@d\n");
**OUTPUT
ab cd ef
HTH,
Rob
Rob Dixon Guest



Reply With Quote

