in reply to Sorting by association, a tail of dependency resolving gone nowhere

No need to implement your own sort.
my %dmap = ( 1 => 0 2 => 4 3 => 5 4 => 3 5 => 1 ); my @tosort = (1,2,3,4,5); my @sorted = sort { $dmap{$a} <=> $dmap{$b} } @tosort;
Update: Corrected typos (thanks Roy Johnson and Ikegami)


holli, /regexed monk/
  • Comment on Re: Sorting by association, a tail of dependency resolving gone nowhere
  • Download Code

Replies are listed 'Best First'.
Re^2: Sorting by association, a tail of dependency resolving gone nowhere
by artist (Parson) on Dec 13, 2005 at 15:54 UTC
    Output of your program comes out: 1,5,4,2,3. It should be: 1,5,3,4,2
    --Artist