From: Matthew J. D. <mda...@se...> - 2003-07-24 06:55:26
|
This is the code I wrote to identify unique memebers of a hash. Hash one could be the messages in email and hash2 the messages in the voicemail. We want to know the unique ones so we can delete them. ******************************** #!/usr/bin/perl -w use strict; my %hash1 = ( field1 => "1", field2 => "32", field3 => "4", field4 => "5", field5 => "434", field6 => "43" ); my %hash2 = ( field1 => "1", field2 => "2", field3 => "3", field4 => "4" ); for (keys %hash1) { my $nomatch = 'true'; my $val1 = $hash1{$_}; for (keys %hash2) { my $val2 = $hash2{$_}; if ($val1 eq $val2) { $nomatch = 'false'; } } if ($nomatch eq 'true') { print "$val1 is unique from hash2\n"; } } print "\n"; for (keys %hash2) { my $nomatch = 'true'; my $val1 = $hash2{$_}; for (keys %hash1) { my $val2 = $hash1{$_}; if ($val1 eq $val2) { $nomatch = 'false'; } } if ($nomatch eq 'true') { print "$val1 is unique from hash1\n"; } } -Matt |