in reply to Sorting geometric coordinates based on priority

use strict; use warnings; # our data in arrays my @rect_x = (3,2,4,0,3,0,4,0,3,2,0,4); my @rect_y = (0,0,0,1,1,0,3,3,3,3,2,2); # create an array 0,1,2,3,....as long as my data is my @unsorted = 0..$#rect_x; # these indexes we sort by Y and then reverse sort by X my @sorted = sort { $rect_x[$b] <=> $rect_x[$a] } sort { $rect_y[$a] <=> $rect_y[$b] } (@unsorted); my $n = 0; for my $i (@sorted){ print "$n $i \t $rect_x[$i] $rect_y[$i] \n"; ++$n; }

yields:

$ perl lowest_sort.pl 0 2 4 0 1 11 4 2 2 6 4 3 3 0 3 0 4 4 3 1 5 8 3 3 6 1 2 0 7 9 2 3 8 5 0 0 9 3 0 1 10 10 0 2 11 7 0 3