Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
I basically want to compare the keys between two hashes to
see which they have in common. If they have one in common I want to
multiply the values of both keys together. I have managed to do the comparing
part, but not sure how to multiply the values. Please can anyone help?? e.g. Ideal output;
The code;dog = 55 cat = 12
my %hash = ( 'dog' => '5', 'sheep' => '10', 'cat' => '3', ); my %hash2 = ( 'dog' => '11', 'budgie' => '1', 'cat' => '4', ); foreach (keys %hash2) { if (exists $hash{$_}) { print "$_ exists"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: comparing keys and values in different hashes
by fruiture (Curate) on Mar 03, 2003 at 14:04 UTC | |
Re: comparing keys and values in different hashes
by broquaint (Abbot) on Mar 03, 2003 at 14:06 UTC | |
Re: comparing keys and values in different hashes
by robartes (Priest) on Mar 03, 2003 at 14:04 UTC | |
Re: comparing keys and values in different hashes
by Russ (Deacon) on Mar 03, 2003 at 18:46 UTC |
Back to
Seekers of Perl Wisdom