http://qs1969.pair.com?node_id=161962


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.
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;
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. ;)

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
    I am assuming that you always want the last element from each inner array.
    Correct!

    Here is an example that you can play with....Hope this works for you.
    Yes, it does - thanks for the new technique

    blyman
    setenv EXINIT 'set noai ts=2'