Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Creating a Slice through a 2 dimensional array

by tomazos (Deacon)
on Sep 29, 2005 at 09:45 UTC ( #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? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-01-29 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?