Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Re: How to determine if something is numeric?

by Limbic~Region (Chancellor)
on Jan 30, 2004 at 19:41 UTC ( #325361=note: print w/replies, xml ) Need Help??


in reply to Re: Re: How to determine if something is numeric?
in thread How to determine if something is numeric?

mifflin,
looks_like_number was introduced in version 1.10 of Scalar::Util. The sub looks like this:
sub looks_like_number { local $_ = shift; # checks from perlfaq4 return 1 unless defined; return 1 if (/^[+-]?\d+$/); # is a +/- integer return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # +a C float return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006 +001 and /^Inf$/i); 0; }
As I stated in my reply - I do not think this meets your requirements because it also handles decimals, scientific notation, NaN, and Inf.

Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://325361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-04-13 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?