Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How do I access only certain elements of a multidimensional array?

by igoryonya (Pilgrim)
on Nov 01, 2015 at 05:53 UTC ( [id://1146605]=note: print w/replies, xml ) Need Help??


in reply to How do I access only certain elements of a multidimensional array?

I incorrectly understood the question at first (thought, you wanted to access the 2nd column), now, I see, you want to access each row from the 2nd to the last element:
my @new_shapes = (); map { push(@new_shapes, [@$_[2..$#$_]]) } @shapes;
if you want to access, say from 1 to 4, just change:
[2..$#$_] to: [1..4]

Replies are listed 'Best First'.
Re^2: How do I access only certain elements of a multidimensional array?
by 2teez (Vicar) on Nov 01, 2015 at 08:43 UTC

    Hi igoryonya,

    map { push(@new_shapes, [@$_[2..$#$_]]) } @shapes;

    I probably not use map like you are using.
    Maybe something like so:

    my @new_shapes = map { [ @{$_}[ 2 .. $#$_ ] ] } @shapes; print join( " " => @{$_} ), $/ for @new_shapes;
    Output:
    triangle polygon blue yellow fuschia c d e f g h i j k Radio

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
      :), yea, it's better, condenses my 2 lines into 1.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-28 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found