tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:
I have a big hash. Some of the values in the hash are the same how do I do to add all the keys for the values that are the same?
An example of what I mean would be:
%hash=(10=>1, 20=>2, 30=>1 40=>2);
After the procedure it should look:
%hash=(40=>1, 60=>2);
If I want to check if a key exist in a hash I do..
if (exists ($hash{$key})) { do.. }
This i very confusing to me. To $hash{$key} should be the same as the value. Could someone explain.
And how do I check if a value exists? I can not reverse the hash since it has many of the same values.
Thank you for your help.
Code tags added by GrandFather
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confusion due to hash
by McDarren (Abbot) on Jan 31, 2006 at 00:26 UTC | |
|
Re: Confusion due to hash
by GrandFather (Saint) on Jan 31, 2006 at 00:57 UTC | |
by duckyd (Hermit) on Jan 31, 2006 at 01:44 UTC | |
by GrandFather (Saint) on Jan 31, 2006 at 01:51 UTC | |
|
Re: Confusion due to hash
by martin (Friar) on Jan 31, 2006 at 03:21 UTC |