Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Extracting columns from a two dimensional array

by Chady (Priest)
on Dec 21, 2004 at 10:39 UTC ( #416425=note: print w/ replies, xml ) Need Help??


in reply to Re: Extracting columns from a two dimensional array
in thread Extracting columns from a two dimensional array

Here's what's happening; a list in scalar context will return its last element.

@array[0..2] will return a list, and in @{}'s scalar context, the last element will be returned, which is the last array ref, that's why you get the last array's item 3 only.

Here's a workaround:

my @array=( [0,1,2,3,4], [25,26,27,28,29], [10,11,12,13,14] ); print @{@array[$_]}[3] for 0 .. 2;

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/
Are you a Linux user in Lebanon? join the Lebanese Linux User Group.


Comment on Re^2: Extracting columns from a two dimensional array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2015-07-31 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (275 votes), past polls