Wednesday, May 14, 2008

Field based sort in perl

Sort records in an array, sort first by the first field and then by the second field. Use a tilde as a field separator.

my @final_array = sort {
(split "~", $a)[0] cmp (split "~", $b)[0]
||
(split "~", $a)[1] cmp (split "~", $b)[1] } @formatted_sorted_array;

No comments: