Sort the indices then use an array slice on each array.
knoppix@Microknoppix:~$ perl -E ' > @items = qw{ dog desk cow }; > @weights = qw{ 20 10 150 }; > @sortedIdx = sort { $items[ $a ] cmp $items[ $b ] } 0 .. $#items; > @items = @items[ @sortedIdx ]; > @weights = @weights[ @sortedIdx ]; > say qq{@items}; > say qq{@weights};' cow desk dog 150 10 20 knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Sort array + keep associated indexes in other array
by johngg
in thread Sort array + keep associated indexes in other array
by johnzzz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |