Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: How to check similarity of two hash tables

by RMGir (Prior)
on Apr 09, 2002 at 14:11 UTC ( #157724=categorized answer: print w/replies, xml ) Need Help??

Q&A > hashes > How to check similarity of two hash tables - Answer contributed by RMGir

They're equal if, as you say, they have the same number of keys AND all the keys in one are in the other.
my $areEqual=1; if(keys %hash1 == keys %hash2) { foreach my $key(keys %hash1) { if(!exists $hash2{$key}) { $areEqual=0; last; } } } if($areEqual) { print "ARE "; } else { print "ARE NOT "; } print "equal\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-02-18 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (253 votes). Check out past polls.

    Notices?