in reply to Re: sorting hash ref
in thread sorting hash ref
andreverse sort { my_cmp($a, $b) } @foo # (1)
are not strictly equivalent: order is reversed for terms comparing as equal.sort { my_cmp($b, $a) } @foo # (2)
For instance:
prints@u = map { [$_, $i++] } (0,0,3,2,2); $" = '-'; print( (map {$_->[1]} reverse sort { $a->[0] <=> $b->[0] } @u), "\n", (map {$_->[1]} sort { $b->[0] <=> $a->[0] } @u), "\n" );
though I believe that most of the times, the correct solution is actually the second one or it just doesn't mind at all!24310 23401
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: sorting hash ref
by halley (Prior) on Jun 10, 2005 at 14:59 UTC |