On Wed, 2002-10-16 at 09:54, Egleton, Gary wrote: > Hi, > > can any one point me at how to compare two hases. > > ie > > hash1 > 1 abc > 2 def > 3 ghi > > hash2 > 1 abc > 2 defzzz > 3 ghi > > I want to take the values for matching keys and see if they are the same if > not write out the value > > so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok > but in key 2 they do not match > > Thanks very much, > > Regards, Gary <snip />
You could always use grep to get the keys that don't match: <code> #!/usr/bin/perl use warnings; use strict; my %hash1 = ( 1 => 'abc', 2 => 'def', 3 => 'ghi', ); my %hash2 = ( 1 => 'abc', 2 => 'defzzz', 3 => 'ghi', ); for my $k (grep { $hash1{$_} ne $hash2{$_} } keys %hash1) { print "at key [$k]: [$hash1{$k}] doesn't equal [$hash2{$k}]\n"; } </code> -- Today is Prickle-Prickle the 70th day of Bureaucracy in the YOLD 3168 Or not. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]