preserve sort order in another list



I have two arrays and i wish to sort the first one numerically, but after
sorting, I would like the second array to be in the same matching order as
the first array.

ie.

@l1={3,1,2};
@l2={'a','b','c'};

@l1 = sort {$a <=> $b} (@l1); # sort list @l1 to be {1,2,3}

# do something to @l2 to make order {'b','c','a'} (preserving the original
mapping with the first list)

There's probably an easy way to do this that i'm not aware of.

Thanks in advance,
Brett.


.



Relevant Pages

  • Re: Sorting routine
    ... n RSHIFT shifts n bits. ... in the output array. ... This would be handy for sign sorting of 2's complement. ... So Radix/Distribution sort is about 1.4 times faster than Sedge's Sort. ...
    (comp.lang.forth)
  • Re: Efficiently Extracting Identical Values From A List/Array
    ... struct SortHelper ... Now sort that array according to NodeIndex: ... running through the data structure and sorting things out. ...
    (comp.lang.cpp)
  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: sorting by multiple criterias (sub-sorting)
    ... and I want to sort these ... > are multiple records with the same name, sorting this group ... > name and same age, ... Quoting from "How do I sort an array by?" ...
    (comp.lang.perl.misc)