#! /usr/bin/perl my $skipOdds = 1000; my $randomOdds = 1000; my $rHash1 = createHash(57000); my $rHash2 = createHash(57000); compareHashes($rHash1, $rHash2); exit; sub createHash { my $size = shift || 100; my $rHashRef = shift || {}; my $key = ''; my $value = ''; for( my $current = 0; $current < $size; $current++ ) { # If rand number comes up 0, skip. next unless int(rand($skipOdds)); $value = $key = sprintf('%X', $current); unless (int(rand($randomOdds))) { $value = sprintf('%X', int(rand($size))); }; $rHashRef->{$key} = $value; } return $rHashRef; #Allows use as RV for assignment; } sub compareHashes { my $rHash1 = shift || {}; my $rHash2 = shift || {}; my %keys; my $currentKey; map {$keys{$_}++} keys(%$rHash1); map {$keys{$_}++} keys(%$rHash2); foreach $currentKey (sort(keys(%keys))) { if ($keys{$currentKey} == 2) { # In both hashes, let's see if it's the same. if ($rHash1->{$currentKey} ne $rHash2->{$currentKey}) { print "Key $currentKey is different\n"; } } else { # Only in one hash, let's see which one. if (exists($rHash1->{$currentKey})) { print "Key $currentKey only in Hash1\n"; } else { print "Key $currentKey only in Hash2\n"; } } } }