in reply to array confusion

$ perl -e' use Data::Dumper; my $A = [[1,2,3],[4,5,6]]; print Dumper $A; @$A = map { [ splice @$_, 0, 2 ], $_ } @$A; print Dumper $A; ' $VAR1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; $VAR1 = [ [ 1, 2 ], [ 3 ], [ 4, 5 ], [ 6 ] ];

Replies are listed 'Best First'.
Re^2: array confusion
by tobyink (Canon) on May 11, 2012 at 06:34 UTC

    Personally I find pop a little more readable.

    use Data::Dumper; my $A = [[1,2,3],[4,5,6]]; @$A = map { $_, [pop @$_] } @$A; print Dumper($A);
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: array confusion
by zerocred (Beadle) on May 11, 2012 at 05:58 UTC
    Now that... is just ingenious. And extremely quick! Thanks!!