in reply to Sorting a hash in one line
But if you wanna get the values in a special order you can use a hashslice on sorted keys in one line
@svalues = @hash{ sort {...} keys %hash }
> But it gives error saying use of implicit split to @_ is deprecated.
scalar split has the ugly side effect to globber @_ (AFAIK at least prior 5.12), you may try something like m/(d)/ or tr/d// to count the "d"s.
UPDATE:
@svalues = @hash{ sort { $a=~tr/d// <=> $b=~tr/d// } keys %hash } should do.
even @svalues = @hash{ sort { $a=~tr/d// <=> $b=~tr/d// } %hash } does what you want (but I can't remember where it's documented) (was wrong)
Cheers Rolf
UPDATE: corrected typo, thx to davido
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting a hash in one line
by ikegami (Patriarch) on Jun 21, 2010 at 08:17 UTC | |
| |
|
Re^2: Sorting a hash in one line
by davido (Cardinal) on Jun 21, 2010 at 07:25 UTC |