I'm afraid I don't understand the part about "scaling this up to check for all three values in %doublet in the %triplet and then print out any rows that are missing." Print out rows from what? Missing from where? I though that elements in %doublet only contain two values each.for my $key ( keys %one_hash ) { next if ( exists( $other_hash{$key} )); # now do something with this $key, which exists only in %one_hash. +.. }
Am I correct to assume that you only compare hash values in the cases where the hash keys match? (If you wanted to compare all hash values, or ones where the keys don't match, that would be a lot more comparisons.)
If your sample code gives any hints, I would expect that you might want something like this:
(I guessed at that based on how you used the various arrays in building the two hashes, assuming that @C1 might be "equivalent" to @C2, and likewise for @D1, @D2.)for my $key ( keys %doublet ) { if ( exists( $triplet{$key} )) { # need to check values next if ( $doublet{$key}[0] eq $triplet{$key}[2] and $doublet{$key}[1] eq $triplet{$key}[1] ); } # get here if $key does not exist in %triplet, # OR if $triplet{$key} is not equivalent to $doublet{$key} print "$key\n"; }
In reply to Re: comparing values in two hashes
by graff
in thread comparing values in two hashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |