in reply to sorting hashes by value

You're near, but if you want to get keys out, you need to put keys in:

@keys = sort { $word_list{$a} <=> $word_list{$b} } keys %word_list;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: sorting hashes by value
by imlou (Sexton) on Nov 08, 2002 at 21:47 UTC
    To print the values with the words...would it be...
    @keysorted = sort {$word_list{$b} <=> $word_list{$a}} keys %word_list; for $i (0..$#keysorted){ for $word(keys %{$keysorted[$i]}){ pritn "$word = $keys[$i]{word}\n";
      There's an easier way to do it:
      foreach my $key ( sort { $word_list{$b} <=> $word_list{$a} } keys %word_list ) { print $key, " ", $word_list{$key}, "\n"; }