Nancy Clark wrote: > > Tom Franklyn <[EMAIL PROTECTED]> 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?
Hi Tom, Nancy. 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>