in reply to Permanently sort a hash
If you don't want to call sort repeatedly, save the result.
my @sorted_keys = sort { $a <=> $b } keys(%foo);
Update: Or if you no longer need the keys:
my @sorted_values = @foo{ sort { $a <=> $b } keys(%foo) };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Permanently sort a hash
by Limbic~Region (Chancellor) on Jun 04, 2009 at 15:16 UTC | |
by ikegami (Patriarch) on Jun 04, 2009 at 15:21 UTC |