( I'm simplifying this a little bit as all but cmp return a value that is both an empty string, and a numerically zero value instead of 0, and a value that is both the string '1' and the numeric value 1. These are the same values you will always get from boolean operators in Perl. You should really only be using the return values for boolean or numeric operations, in which case the difference doesn't really matter. )
$a $b Type of Match Implied Matching Code
====== ===== ===================== =============
(overloading trumps everything)
Code[+] Code[+] referential equality $a == $b
Any Code[+] scalar sub truth $b−>($a)
Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b]
Hash Array hash slice existence grep {exists $a−>{$_}} @$b
Hash Regex hash key grep grep /$b/, keys %$a
Hash Any hash entry existence exists $a−>{$b}
Array Array arrays are identical[*]
Array Regex array grep grep /$b/, @$a
Array Num array contains number grep $_ == $b, @$a
Array Any array contains string grep $_ eq $b, @$a
Any undef undefined !defined $a
Any Regex pattern match $a =~ /$b/
Code() Code() results are equal $a−>() eq $b−>()
Any Code() simple closure truth $b−>() # ignoring $a
Num numish[!] numeric equality $a == $b
Any Str string equality $a eq $b
Any Num numeric equality $a == $b
Any Any string equality $a eq $b
+ − this must be a code reference whose prototype (if present) is not ""
(subs with a "" prototype are dealt with by the 'Code()' entry lower down)
* − that is, each element matches the element of same index in the other
array. If a circular reference is found, we fall back to referential
equality.
! − either a real number, or a string that looks like a number
# header
use warnings;
use strict;
#create a hash of letters
my %my_hash_lookup;
my $letter_counter=0;
foreach my $letters ('A'..'ZZ')
{
#print "$letters \n";
$letter_counter++;
my $key = $letters;
my $keyValue = $letter_counter;
$my_hash_lookup{$key}=$keyValue;
}
my $size = keys %my_hash_lookup;
print "hash size: $size ...\n";
#get number value of string letters
my $my_hash_value1 = $my_hash_lookup{"A"};
my $my_hash_value2 = $my_hash_lookup{"B"};
if ( (defined $my_hash_value1) && (defined $my_hash_value2))
{
if ($my_hash_value1 == $my_hash_value2)
{
#equal
}
elsif ($my_hash_value1 > $my_hash_value2)
{
#greater than
}
elsif ($my_hash_value1 < $my_hash_value2)
{
#less than
}
}