in reply to Comparing keys in 3 different hashes and if they are the same them print the values on one line

G'day NewLondonPerl1,

You don't need to iterate through each hash, you only need to iterate through one of them because if the key doesn't exist in one then the condition of the key existing in all three is not met. If they vary substantially in size, pick the one with the least number of keys. The guts of your code will look something like:

for (keys %hash1) { if (exists $hash2{$_} and exists $hash3{$_}) { print $hash1{$_}, $hash2{$_}, $hash3{$_}; } }

You don't need to sort for the functionality to work. I'll leave you to format the output.

-- Ken

  • Comment on Re: Comparing keys in 3 different hashes and if they are the same them print the values on one line
  • Download Code

Replies are listed 'Best First'.
Re^2: Comparing keys in 3 different hashes and if they are the same them print the values on one line
by NewLondonPerl1 (Acolyte) on Mar 01, 2013 at 04:48 UTC
    Thanks ever so much Ken. This is xactly what I am looking for. Thanks for your help :-)