in reply to Re: Re: How to determine if something is numeric?
in thread How to determine if something is numeric?
As I stated in my reply - I do not think this meets your requirements because it also handles decimals, scientific notation, NaN, and Inf.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; }
Cheers - L~R
|
|---|