in reply to Re: Shifting of 2D array slices
in thread Shifting of 2D array slices

@bigarray = map [ map split( /\*/ ), @$_ ], @bigarray;
The second map statement (map split(/\*/), @$_) in the reply of jwkrahn is not necessary. In addition, it has the side effect of splitting all elements (strings) of the referenced array even though the intent seems to be to split only the first. None of the other elements contains the particular split pattern being used, so the extraneous splits have no effect; however, this approach depends on the assumption that the split pattern never appears in the other elements, and no one knows what the future may hold.

(Note that the test data in @bigarray are slightly different.)

>perl -wMstrict -le "use Data::Dumper; my @bigarray = ( [ '123*jeff', 'tortoise', 'qwe*rty', ], [ '456*john', 'parrot', 'aze*rty', ], [ '789*jane', 'budgie', 'abc*def', ], ); @bigarray = map [ map split(/\*/), @$_ ], @bigarray ; print Dumper \@bigarray; " $VAR1 = [ [ '123', 'jeff', 'tortoise', 'qwe', 'rty' ], [ '456', 'john', 'parrot', 'aze', 'rty' ], [ '789', 'jane', 'budgie', 'abc', 'def' ] ]; >perl -wMstrict -le "use Data::Dumper; my @bigarray = ( [ '123*jeff', 'tortoise', 'qwe*rty', ], [ '456*john', 'parrot', 'aze*rty', ], [ '789*jane', 'budgie', 'abc*def', ], ); @bigarray = map [ split(/\*/, $_->[0]), @$_[ 1 .. $#$_ ] ], @bigarray ; print Dumper \@bigarray; " $VAR1 = [ [ '123', 'jeff', 'tortoise', 'qwe*rty' ], [ '456', 'john', 'parrot', 'aze*rty' ], [ '789', 'jane', 'budgie', 'abc*def' ] ];
Actually, I would prefer an approach using a for loop such as that of davidrw. In particular, the approach using splice can easily be modified to split any arbitrary element; this can also be done with the map approach, but with less concision.