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 --- allan <[EMAIL PROTECTED]> wrote: > hi > > is it possible to sort by the values in a hash if > those values might > be identical ? > please try example below whcih will indeed sort the > way i want, but > will (obviously) discard duplicate keys in my > reverse hash; > > anyone have a good idea for this ? > > ../allan > _________ > > %test = ( > abc => 1230, > def => 456, > cbs => 456, > agr => 111, > ); > > my %reverse_test = reverse %test; > my @sorted_keys = sort { $a <=> $b } keys > %reverse_test; > > foreach my $key (@sorted_keys) { > print "$key => $reverse_test{$key}\n" > } > > __END__ __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com