August 1999 | Return to the Perl Hardware Store | Slide #4 |
0 1 2 3 4 5 Albert Mark Morton Babe Nat Larry Einstein Dominus Zeemeister Ruth Torkington Wall
Solution: Sort the list of indices into order:
@indices = sort {$last[$a] cmp $last[$b]} (0 .. $#last);
@indices is now 1, 0, 3, 4, 5, 2
Then slice:
@sorted = @first[@indices];
Result: Mark, Albert, Babe, Nat, Larry, Morton.
Next | Copyright © 1999 M-J. Dominus |