Be aware that looks_like_number() returns true for strings like '9e0' and '9', but false for strings like '0x9'.
I don't know if it has any impact on what you are doing but your comp() subroutine will return true when comparing the numbers 9 and 0x9, will return true when comparing the strings '9e0' and '9', but will return false when comparing the strings '0x9' and '9' (or when comparing the string '0x9' to the number 9).
use strict;
use warnings;
use Scalar::Util qw(looks_like_number);
my $x1 = '0x9';
my $x2 = 0x9;
my $x3 = '9';
my $x4 = '9e0';
my $x5 = 9e0;
print "1: ", comp($x1, 9), "\n";
print "2: ", comp($x2, 9), "\n";
print "3: ", comp($x3, 9), "\n";
print "4: ", comp($x4, 9), "\n";
print "5: ", comp($x5, 9), "\n";
sub comp {
my ($a, $b) = @_;
if (looks_like_number($a) && looks_like_number($b)) {
return ($a == $b);
}
else {
return ($a eq $b);
}
}
__END__
Outputs:
1:
2: 1
3: 1
4: 1
5: 1
Cheers,
Rob