http://qs1969.pair.com?node_id=496026


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