Cirollo has asked for the wisdom of the Perl Monks concerning the following question:
I have a 2D array, and I want to return just a "column" of the array. For example,
So, I want some function that would return (1, 4, 7). The best I've been able to do is this:@ary = ( [1, 2, 3], [4, 5, 6], [7, 8, 9] );
This doesn't seem very "nice," and I don't like the map solution because it isn't terribly suggestive of what the code actually does. Anyone have a better way to do this? Maybe something with hash slices? @ary[0..$#ary][0] doesn't work.map { $_->[0] } @ary[0..$#ary]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Slices of 2D arrays?
by hardburn (Abbot) on Jun 06, 2003 at 15:26 UTC | |
(jeffa) Re: Slices of 2D arrays?
by jeffa (Bishop) on Jun 06, 2003 at 15:36 UTC | |
Re: Slices of 2D arrays?
by broquaint (Abbot) on Jun 06, 2003 at 15:29 UTC | |
Re: Slices of 2D arrays?
by BrowserUk (Patriarch) on Jun 06, 2003 at 15:52 UTC |
Back to
Seekers of Perl Wisdom