Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:
e.g. "ger" <--> "german"
e.g. "ara" <--> "arabic"
e.g. "eng" <--> "english"
I always only know the left (e.g. "ger") or right value (e.g. "german") and I have to get the other value.
I tried to solve this problem with a hash. But then I have the problem that I do not get the key when I have the value. Here an example.
#!/usr/bin/perl use strict; use warnings; my %languages = ( "ger" => "german", "ara" => "arabic", "eng" => "english" ); # with the key it is easy to get to the value foreach my $key (keys %languages ) { print "$key <--> $languages{$key}" . "\n"; } # but how do I get key if I only have the value # e.g. I know "german", but how do I get "ger"? foreach my $value (values %languages ) { print "$value <--> ???" . "\n"; }
How would you solve this problem?
Thank you very much Dirk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One to one relationship
by Anonymous Monk on Oct 30, 2009 at 10:21 UTC | |
|
Re: One to one relationship
by toolic (Bishop) on Oct 30, 2009 at 13:35 UTC | |
|
Re: One to one relationship
by herveus (Prior) on Oct 30, 2009 at 11:32 UTC | |
|
Re: One to one relationship
by ikegami (Patriarch) on Oct 30, 2009 at 15:15 UTC | |
|
Re: One to one relationship
by biohisham (Priest) on Oct 30, 2009 at 15:07 UTC | |
by ack (Deacon) on Oct 30, 2009 at 16:16 UTC | |
|
Re: One to one relationship
by wol (Hermit) on Nov 02, 2009 at 17:29 UTC |