in reply to sorting of two perl arrays
Create an array of indices sorted by @b and then use it to reorder both arrays:
@a = (1,5,3);; @b = (5,2,1);; @sortedIndices = sort{ $b[ $a ] <=> $b[ $b ] } 0 .. $#b;; @a = @a[ @sortedIndices ];; @b = @b[ @sortedIndices ];; print "@a\n@b";; 3 5 1 1 2 5
|
|---|