in reply to Hash sorting (by value) woes

That's going to evaluate each side of the spaceship operator (<=>) to 1 and make no changes.

You really want something like:

map { print "$etcpw->{$_}\n"; } sort { my ($first) = ($etcpw->{$a} =~ /:(\d+)/); my ($second) = ($etcpw->{$b} =~ /:(\d+)/); $first <=> $second } keys %{$etcpw};

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: Hash sorting (by value) woes
by sschneid (Deacon) on Feb 24, 2005 at 17:05 UTC

    That makes sense. Thanks.

    -s.

      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};
        Of course, if you really want to use map instead of foreach:
        print map {"$etcpw->{$_}\n"} sort { $a->[1] <=> $b->[1] } map { $etcpw->{$_} =~ /:(\d+)/; [ $_, $1 ] } keys %{$etcpw};

        Caution: Contents may have been coded under pressure.