in reply to Re: Finding a hash key from the value (reverse lookup)
in thread Finding a hash key from the value (reverse lookup)

You couldn't always use reverse.

The question asked about non-unique values, thus you end up losing keys that are appropriate values. In this situation, you do not have a 1-1 function so reverse is very bad.

ALL HAIL BRAK!!!

  • Comment on Re: Re: Finding a hash key from the value (reverse lookup)

Replies are listed 'Best First'.
non-1:1 mappings
by Anonymous Monk on Jan 23, 2001 at 02:23 UTC

    Well, building a useful reverse index in cases where you don't have a 1:1 mapping isn't too bad (although not as elegant):

    (given %index)

    my %revindex; for my $revpair (map { [ $index{$_}, $_ ] } keys(%index)) { push @{$revindex{$revpair->[0]}}, $revpair->[1]; }

    There are probably simpler ways to do even that, however.