develooper Front page | perl.beginners | Postings from February 2002

ignoring some fields in a comparision of hashes

Thread Next
From:
Chas Owens
Date:
February 7, 2002 10:17
Subject:
ignoring some fields in a comparision of hashes
Message ID:
1013105807.9443.99.camel@tert.icallinc.com
I have two hashes (%a and %b) that contain data for one person from two
different systems and I want to compare these hashes to see if the
systems are out of sync.  The catch is I know that some of the fields
will always be different and I want to ignore those fields.  Below is my
solution, does anyone have a better way of doing this? BTW: there are a
lot of fields currently with more being added as time goes on and the
number of fields I want to ignore will stay pretty much the same).

<example>
my @ignore = ("key1", "key2");

KEYS: foreach my $key (keys %a) {
	foreach my $ignore (@ignore) {
		next KEYS if $key eq $ignore;
	}
	if ($a{$key} ne $b{$key}) {
		print "$key is different ($a{$key}, $b{$key})\n";
	}
}
</example>

-- 
Today is Pungenday the 38th day of Chaos in the YOLD 3168
All Hail Discordia!

Missle Address: 33:48:3.521N  84:23:34.786W


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About