in reply to seeking different ways to slice a 2-d array
I always found splice to be a good way to slice an
array. Here is an example that you can play with. I
am assuming that you always want the last element from
each inner array.
The third argument of '1' for splice is not necessary in this case, but i recommend keeping it in case you decide to remove only one element from any other position. ;)use strict; use Data::Dumper; my @arry = ( [qw(one two three)], [qw(foo bar baz)], ); my @new; push @new, splice(@$_,$#$_,1) for @arry; print Dumper \@new;
Hope this works for you.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (jeffa) Re: seeking different ways to slice a 2-d array
by belden (Friar) on Apr 25, 2002 at 17:01 UTC |
In Section
Seekers of Perl Wisdom