in reply to I'm splitting a scalar and putting the results in an array. Why is the first element empty?

The explanations are all very interesting and believable, but should equally apply to say version 5.0005 of Perl. Unfortunately they don't -- on a whim, I ran something similar against Perl 5.0005 running on an old Solaris box, and the code DWIMed relative to the OP, i.e. the '\* [' separator did not get entered into the array returned by split. This suggests to me that yet something else is afoot.

-M

Free your mind

  • Comment on Re: I'm splitting a scalar and putting the results in an array. Why is the first element empty?

Replies are listed 'Best First'.
Re^2: I'm splitting a scalar and putting the results in an array. Why is the first element empty?
by Lu. (Hermit) on Aug 13, 2006 at 08:04 UTC
    I think they apply, unless I am mistaken. Granted, english is not my first language, so I may have misunderstood your post, but it is a normal behaviour for split not to enter the separator in the returned array.
    For example, this bit of code :
    my $string = "aa:bb:cc:dd:ee:ff:gg:hh"; my @table = split /:/ , $string; print "@table\n";
    would print
    aa bb cc dd ee ff gg hh
      It does if you have parans in the regex.
      my @table = split /(:)/, $string
      --Artist