[Chicago-talk] Array slices

Randal L. Schwartz merlyn at stonehenge.com
Sun Nov 5 05:05:03 PST 2006


>>>>> "Jay" == Jay Strauss <me at heyjay.com> writes:

Jay> Is there any way other than iteration to get an array slice of a
Jay> multi-dimensional array?

Do you consider "map" to be iteration?

Jay> For example, I'd like to create a slice out of the 2nd element of each
Jay> inner array, so that my result would be (2,4,6).

Jay> @a = ([1,2],[3,4],[5,6]);

Jay> print join @a[][1],"\n";  # doesn't work
Jay> print join @a[0..2][1],"\n"; #doesn't work

my @a = ([1,2],[3,4],[5,6]);
my @result = map $_->[1], @a;
print "@result\n";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


More information about the Chicago-talk mailing list