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
In reply to Re: sorting of two perl arrays
by BrowserUk
in thread sorting of two perl arrays
by rahulm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |