http://qs321.pair.com?node_id=1130882

saintmike has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone explain why the @options array in the following code snippet doesn't gobble up the empty field at the end?
my $str = "foo:bar:"; my( $a, @options ) = split /:/, $str; my( $b, $c, $d ) = split /:/, $str; use Data::Dumper; print Dumper( [ $a, \@options ] ); print Dumper( [ $b, $c, $d ] );
$VAR1 = [ 'foo', [ 'bar' ] ]; $VAR1 = [ 'foo', 'bar', '' ];
This seems to have to do with split(), as
my( $a, @options ) = ( "foo", "bar", "" ); my( $b, $c, $d ) = ( "foo", "bar", "" ); use Data::Dumper; print Dumper( [ $a, \@options ] ); print Dumper( [ $b, $c, $d ] );
gobbles up everything correctly:
$VAR1 = [ 'foo', [ 'bar', '' ] ]; $VAR1 = [ 'foo', 'bar', '' ];