in reply to How best to compare hash values?

Just go through all the keys in one hash and compare the values.
foreach my $key ( sort keys %hash1 ) { print $hash1{$key} - $hash2{$key}, "\n"; }
Problems may occur if a key is not present in both hashes, though.

Replies are listed 'Best First'.
Re^2: How best to compare hash values?
by doug (Pilgrim) on May 06, 2010 at 13:27 UTC

    I generally do it this way too, but I check all keys that are in both. Something like:

    my %union = ( %hash1, %hash2 ); my @keys = sort keys %union; undef %union; foreach my $key ( @keys ) { if ( ! exists $hash1{$key} ) { print "key $key is not in hash 1\n"; } elsif ( ! exists $hash2{$key} ) { print "key $key is not in hash 2\n"; } ....

    - doug