in reply to Problem with a sort result
Hello kzwiz,
Personally I've never seen `-` used as the comparison operator in a custom sort. This doesn't mean anything other than I've never seen it, but I do find the standard numerical comparison operator (`<=>`) provides your expected results:
$ perl -E' $h={foo=>{bar=>13908480193},baz=>{bar=>771918754},qux=>{bar=>288170793 +399}}; say "$_: $h->{$_}->{bar}" for sort { $h->{$b}->{bar} - $h->{$a}->{bar} + } keys %$h; ' foo: 13908480193 baz: 771918754 qux: 288170793399
Hope this helps!$ perl -E' $h={foo=>{bar=>13908480193},baz=>{bar=>771918754},qux=>{bar=>288170793 +399}}; say "$_: $h->{$_}->{bar}" for sort { $h->{$b}->{bar} <=> $h->{$a}->{ba +r} } keys %$h; ' qux: 288170793399 foo: 13908480193 baz: 771918754
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem with a sort result
by Discipulus (Canon) on Jan 14, 2016 at 17:57 UTC | |
by anonymized user 468275 (Curate) on Jan 14, 2016 at 23:31 UTC | |
by rdfield (Priest) on Jan 15, 2016 at 07:57 UTC | |
by Discipulus (Canon) on Jan 15, 2016 at 09:00 UTC | |
by kzwix (Sexton) on Jan 27, 2016 at 14:32 UTC | |
|