# Strict use strict; use warnings; # Libraries; use Data::Dumper; # Main program $| = 1; my $phash = { }; my $parray = [ ]; my $ndiff = 0; # Save all single characters and character pairs as hash keys for (my $i = 0; $i < 256; $i++) { save_to_hash_and_array($i); for (my $j = 0; $j < 256; $j++) { save_to_hash_and_array($i, $j); } } # Test all single characters for (my $i = 0; $i < 256; $i++) { my $is_same = hash_matches_array($i)? 1: 0; $is_same or $ndiff++; printf "%s", $is_same? ".": "@"; } print "\n\n"; # Test all character pairs for (my $i = 0; $i < 256; $i++) { for (my $j = 0; $j < 256; $j++) { my $is_same = hash_matches_array($i, $j)? 1: 0; $is_same or $ndiff++; printf "%s", $is_same? ".": "@"; } } print "\n\n"; print "Number of mismatches = $ndiff\n"; # Uncomment out this line to see a lot of strange character print "Type [RETURN] to see a dump of the hash ... "; ; print Dumper($phash), "\n"; sub save_to_hash_and_array { my ($idx0, $idx1) = @_; my $key = chr($idx0); defined($idx1) and $key .= chr($idx1); my $value = sprintf "(%s:%s)", $idx0, ($idx1 || "blank"); $phash->{$key} = $value; $parray->[$idx0 + 256*($idx1||0)] = $value; } sub hash_matches_array { my ($idx0, $idx1) = @_; my $key = chr($idx0); defined($idx1) and $key .= chr($idx1); my $hval = $phash->{$key}; my $aval = $parray->[$idx0 + 256*($idx1||0)]; return ($hval eq $aval)? 1: 0; }