However, I am guessing you have an array of arrayrefs.
...
sort { $b->[0] <=> $a->[0] } @array
Assuming, like you said, an array of arrayrefs—which is a good assumption, I think—this code would try to order the array refs in @array by the first elements contained in the arrays they reference.
That seems very unlikely to be what he wants.
Update:
If he wants to sort the array referenced by $array[0], the code I gave will work. If he wants to sort all of his "columns," he should sort the indexes based on his sorting column using something like:
And then use the array of sorted indexes to map the sorted order onto the actual columns with something like this:my @indexes = sort {$array[0]->[$b] <=> $array[0]->[$a]} (0..$#{$array +[0]});
my @sort = map { my $a = $_; [ map { $t->[$_] } @indexes ] } @array;
It's up to him to be sure the "columns" are the same length, of course.
In reply to Re^2: sorting the column of array element
by sauoq
in thread sorting the column of array element
by anonym
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |