in reply to Re: Sorting a hash in one line
in thread Sorting a hash in one line
Sorting the list returned by %hash is quite wrong.
use strict; use warnings; my %hash = map { $_ => 1 } qw( foo food dood ); my @svalues1 = @hash{ sort { $a=~tr/d// <=> $b=~tr/d// } keys %hash }; my @svalues2 = @hash{ sort { $a=~tr/d// <=> $b=~tr/d// } %hash }; print(0+@svalues1, "\n"); # 3 print(0+@svalues2, "\n"); # 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |