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};
In reply to Re^3: Hash sorting (by value) woes
by ikegami
in thread Hash sorting (by value) woes
by sschneid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |