Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi,
any ideas for sorting a two-dimentional array by second dimention i.e.
array->|rows|cols|
I want to say sort by rows by column 2 for example.. i mean one-liner so that i can insert in
foreach my $rowNumber (...xxx...) .... thanx in advance

Replies are listed 'Best First'.
Re: sort by column
by joealba (Hermit) on Feb 22, 2002 at 14:43 UTC
    my @array; @array[0] = [4, 2, 6]; @array[2] = [2, 1, 7]; @array[1] = [6, 9, 3]; @array[3] = [1, 1, 1]; use Data::Dumper; foreach (sort { $a->[2] <=> $b->[2] } @array) { print Dumper($_); }
Re: sort by column
by Fletch (Bishop) on Feb 22, 2002 at 17:17 UTC
    $ perldoc -q 'sort an array' Found in /usr/lib/perl5/5.6.1/pod/perlfaq4.pod How do I sort an array by (anything)?