Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Creating a Slice through a 2 dimensional array

by tomazos (Deacon)
on Sep 29, 2005 at 09:45 UTC ( [id://496026]=note: print w/replies, xml ) Need Help??


in reply to Creating a Slice through a 2 dimensional array

So, $sortarr[0..10] is just plain wrong. (Does it compile? Confused.) It should be @sortarr[0..10] because a slice is plural (@) not singular ($).

I can see what you are trying to do. You want the third column of the first ten lines in an array.

You need to invert the Array-of-Arrays.

Rather than an array of the split lines, you need an array of each column.

You can do this with map, rather than a push split as you parse the file.

Once you have it inverted you would say @sortarr[3]->[0..10] to get what you want.

Update: Oh! I see why $sortarr[0..10] is compiling. It evaluates the array 0..10 in a scalar context, which gives you its length. It then uses this length as the index to a single element of @sortarr. use warnings may have helped. -Andrew.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found