in reply to sort an array according to another array

If I read your question correctly, you have something like this?
use strict; my @universe = sort complex_sort (1001 ... 5000); my @random_offsets = (503,1083,260,5,101); my @subset = @universe[@random_offsets]; print "unsorted subset: @subset\n"; # Want subset in same complex_sort order as @universe # Can do a quick sort on the index, as @universe # is already in the order we want! # Option 1: @subset = @universe[sort( {$a <=> $b} @random_offsets)]; print "sorted subset: indicies: @subset\n"; # But if unable to determine the universe indicies # in advance, we might have to sort the subset once # Option 2: @subset = sort complex_sort @subset; print "sorted subset: complex_sort @subset\n"; sub complex_sort { return $b <=> $a; }
Regards

Jeff