in reply to numeric comparison
This is the function I used to use for this.
sub is_numeric{ use POSIX (); !(POSIX::strtod($_[0]))[1]; }
However, if you download and build the latest cpan version of Scalar::Util (the version that comes with 5.8.0 doesn't have it), it provides access to perl's internal looks_like_number(); which ought to be quicker than either strtod() or a regex.
NOTE: If your not set up to build XS modules, then List::Util and Scalar::Util will silently fall back to using Perl implementations of the functions they provide. In the case of Looks_like_number(), this is a regex.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: numeric comparison
by Zaxo (Archbishop) on Jul 15, 2003 at 14:44 UTC | |
by BrowserUk (Patriarch) on Jul 15, 2003 at 15:06 UTC |