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', '' ];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Mystery interaction between split and gobbling arrays
by toolic (Bishop) on Jun 17, 2015 at 20:52 UTC | |
by saintmike (Vicar) on Jun 17, 2015 at 23:12 UTC | |
Re: Mystery interaction between split and gobbling arrays
by Discipulus (Canon) on Jun 17, 2015 at 20:58 UTC | |
Re: Mystery interaction between split and gobbling arrays
by kcott (Archbishop) on Jun 17, 2015 at 21:03 UTC | |
by saintmike (Vicar) on Jun 17, 2015 at 23:14 UTC | |
by kcott (Archbishop) on Jun 18, 2015 at 04:23 UTC | |
by saintmike (Vicar) on Jun 18, 2015 at 17:25 UTC | |
by kcott (Archbishop) on Jun 19, 2015 at 05:44 UTC |
Back to
Seekers of Perl Wisdom