Subject: | looks_like_number and overloaded objects |
looks_like number will return false on objects that stringify or
numerify to numbers.
use Scalar::Util qw(looks_like_number);
my $foo = Foo->new;
print "The number is: ", 0+$foo, "\n";
print "The string is: ", "$foo", "\n";
print "Looks like a number: ",
looks_like_number($foo) ? "yes" : "no", "\n";
package Foo;
sub new { return bless {} };
use overload
"+0" => sub { 123 },
'""' => sub { "123" },
fallback => 1;