Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I know how to do a simple sort on hash values: @sorted = sort { $hashed{$a} <=> $hashed{$b} } keys %hashed; but I need need to have the keys also sorted in case of (and my application will have many) equal values. For example, $hashed{'a'} = 1; $hashed{'b'} = 3; $hashed{'c'} = 2; $hashed{'d'} = 2; $hashed{'e'} = 1; $hashed{'f'} = 2; I need to come up with (in a report): a 1 e 1 c 2 d 2 f 2 b 3 I imagine a simple way to do this exists. Thank you for your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash sort with equal values
by I0 (Priest) on Jul 03, 2001 at 10:04 UTC | |
|
Re: Hash sort with equal values
by Zaxo (Archbishop) on Jul 03, 2001 at 10:07 UTC | |
|
Re: Hash sort with equal values
by dvergin (Monsignor) on Jul 03, 2001 at 10:06 UTC | |
|
Re: Hash sort with equal values
by mischief (Hermit) on Jul 03, 2001 at 16:47 UTC |