# Get the value for each key for my $key (keys %languages ) { print "$key --> $languages{$key}\n"; } # Get the keys for each value for my $value ( values %languages ) { for my $key ( keys %languages ) { print "$key --> $value\n" if $languages{$key} eq $value; } }
You need to visit all the keys to do a reverse matching. In general, you also have to worry about the case where keys map to the same value.
Since you have a one-to-one mapping, you can use a pair of hashes to do efficient lookups in both directions. The downside is that you must keep the two hashes in sync.
In reply to Re: One to one relationship
by ikegami
in thread One to one relationship
by Dirk80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |