Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

(jeffa) Re: seeking different ways to slice a 2-d array

by jeffa (Bishop)
on Apr 25, 2002 at 14:19 UTC ( #161962=note: print w/replies, xml ) Need Help??


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'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161962]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-02-05 22:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?