How do I sort a hash (optionally by value instead of key)?

[email protected] (Mark) Sat, 5 Jan 2008 09:29:18 -0700
Newsgroups perl.perlfaq.workers
Organization Genre 121
Message-ID <[email protected]>
The following is given in the FAQ on how to sort a hash...

    my @keys = sort { $a cmp $b } keys %hash;

    foreach my $key ( @keys )
             {
             printf "%-20s %6d\n", $key, $hash{$value};
             }

Shouldn't that be $hash{$key} ?

Also, I think it would be better to use K&R bracketing instead
of GNU bracketing.

Thanks for listening.

- Mark