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

You have a seperator sequence so there must be something to the left of it - even if it is very short :). NOte that there doesn't have to be anything after. Consider:

use warnings; use strict; my $test =",124,456,7890"; print "Test string: >$test<\n"; my @matches = split m/(,)/, $test; print "Item $_ is >$matches[$_]<\n" for 0..$#matches;

Prints:

Test string: >,124,456,7890< Item 0 is >< Item 1 is >,< Item 2 is >124< Item 3 is >,< Item 4 is >456< Item 5 is >,< Item 6 is >7890<

DWIM is Perl's answer to Gödel
  • Comment on Re: I'm splitting a scalar and putting the results in an array. Why is the first element empty?
  • Select or Download Code