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 ] );
This seems to have to do with split(), as$VAR1 = [ 'foo', [ 'bar' ] ]; $VAR1 = [ 'foo', 'bar', '' ];
gobbles up everything correctly:my( $a, @options ) = ( "foo", "bar", "" ); my( $b, $c, $d ) = ( "foo", "bar", "" ); use Data::Dumper; print Dumper( [ $a, \@options ] ); print Dumper( [ $b, $c, $d ] );
$VAR1 = [ 'foo', [ 'bar', '' ] ]; $VAR1 = [ 'foo', 'bar', '' ];
Back to
Seekers of Perl Wisdom