in reply to Re^2: Hash sorting (by value) woes
in thread Hash sorting (by value) woes
Here's an optmization that only executes the regexp once per string:
@sorted_keys = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { $etcpw->{$_} =~ /:(\d+)/; [ $_, $1 ] } keys %{$etcpw}; print "$etcpw->{$_}\n" foreach @sorted_keys;
We can even drop a step:
print "$etcpw->{$_->[0]}\n" foreach sort { $a->[1] <=> $b->[1] } map { $etcpw->{$_} =~ /:(\d+)/; [ $_, $1 ] } keys %{$etcpw};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hash sorting (by value) woes
by Roy Johnson (Monsignor) on Feb 24, 2005 at 17:33 UTC | |
by ikegami (Patriarch) on Feb 24, 2005 at 17:42 UTC | |
by Roy Johnson (Monsignor) on Feb 24, 2005 at 18:03 UTC |