> Scalar::Util's looks_like_number method will do what you want.
Scalar::Util uses a regex to get the answer. I'm not sure why snoopy's request has that requirement, but...
ben@Tyr:~$ perl -wne'print if /sub looks_like_number/../}/' `perldoc - +l Scalar::Util` sub looks_like_number { local $_ = shift; # checks from perlfaq4 return 0 if !defined($_) or ref($_); 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; }
-- Human history becomes more and more a race between education and catastrophe. -- HG Wells
In reply to Re^2: check if its a number
by oko1
in thread check if its a number
by m.y
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |