in reply to How to determine if something is numeric?
If I've understood your specs correctly:
use Scalar::Util 'looks_like_number'; if (0 != substr($var,0,1) and looks_like_number($var)) { # it's a number }
Update: As sporty pointed out below, this breaks on negative numbers. I didn't see that dash in your post. Here's the fix:
use Scalar::Util 'looks_like_number'; if ($var !~ /^-?0/ && looks_like_number($var)) { # it's a number }
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to determine if something is numeric?
by mifflin (Curate) on Jan 30, 2004 at 19:34 UTC | |
by Limbic~Region (Chancellor) on Jan 30, 2004 at 19:41 UTC | |
by PodMaster (Abbot) on Jan 30, 2004 at 19:40 UTC | |
|
Re: Re: How to determine if something is numeric?
by exussum0 (Vicar) on Jan 30, 2004 at 19:42 UTC |