I am trying to find out if an input is number or string. I came across
use Scalar::Util qw(looks_like_number);
my $name = 11;
print looks_like_number ($name);
This is what the documentation says:
Returns true if perl thinks EXPR is a number. See "looks_like_number" in perlapi.
The link to perlapi in this quote is not really helping us a lot unfortunately:
Test if the content of an SV looks like a number (or is a number). Inf and Infinity are treated as numbers (so will not issue a non-numeric warning), even if your atof() doesn't grok them. Get-magic is ignored.
I32 looks_like_number(SV *const sv)
In my case, your code will return an integer that is not
0, which is true.
4352when I used
All of these are true, so that works.
0, which is not true.
1for anything that did not look like a number.
'1e1'and it printed
4, which is a true value, and the input looked like a number in scientific notation.
So, I'd say it always returns something true if Perl thinks the input looks like a number, though I do not know what exactly that true value represents. I cannot confirm that it also returns true with a name.