Re: [MacPerl-AnyPerl] sorting by hash value
[email protected] (allan) Mon, 23 Sep 2002 21:00:25 +0200
| Newsgroups | perl.macperl.anyperl |
|---|---|
| Message-ID | <[email protected]> |
thank you
works brilliantly!
../allan
David Iberri wrote:
>
> Hi Allan,
>
> How about sorting the hash keys by their value,
> instead of inverting the hash?
>
> my %presVocab = (
> 'nuclear' => 'nuculear',
> 'terror' => 'terra',
> 'horror' => 'horra'
> );
>
> my @keys_sorted_by_value = sort {
> $presVocab{$a} cmp $presVocab{$b}
> } keys %presVocab;
>
> foreach my $key(@keys_sorted_by_value) {
> print "$key => $presVocab{$key}\n";
> }
>
> Cheers,
> David Iberri