in reply to sorting hashes by value
@words = sort { $word_list{$a} <=> $word_list{$b} } keys %word_list;
This works because keys() returns a list of keys for the %word_list hash. Then the sort block compares these keys by looking up their value in %word_list. The return from sort is the list of keys sorted by their values.
If you really wanted a list of sorted values, that's just:
@values = sort values %word_list;
-sam
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sorting hashes by value
by imlou (Sexton) on Nov 08, 2002 at 21:27 UTC | |
by samtregar (Abbot) on Nov 08, 2002 at 21:36 UTC | |
by waswas-fng (Curate) on Nov 08, 2002 at 21:44 UTC | |
by imlou (Sexton) on Nov 08, 2002 at 21:58 UTC | |
by Orsmo (Beadle) on Nov 08, 2002 at 22:55 UTC |