in reply to Sort a 2D array based on 2 columns
This is a FAQ. See perlfaq4 or perldoc -q sort:
Found in /usr/local/lib/perl5/5.10.0/pod/perlfaq4.pod
How do I sort an array by (anything)?If you need to sort on several fields, the following paradigm is useful.@sorted = sort { field1($a) <=> field1($b) || field2($a) cmp field2($b) || field3($a) cmp field3($b) } @data;
Change that to use references and you're done.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort a 2D array based on 2 columns
by doug (Pilgrim) on Apr 26, 2009 at 18:48 UTC |