in reply to Checking whether a $var is a number
A string that can't be parsed as a number at all will be zero. So, how about something like this:
In a real application, you will have a more precise definition of what you want. For example, a spreadsheet formula might be a literal number or a cell reference. For such things, you can write rules to match what your application needs and is documented to accept.if ($x==0 && substr($x,0,1) ne '0') { # deal with non-number } else { # deal with number }
—John
Update:fixed typo in substr, reported by dga. Yea, I typed it without checking perlfunc, and I rarely use substr in real code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Checking whether a $var is a number
by George_Sherston (Vicar) on Sep 05, 2001 at 01:37 UTC | |
by John M. Dlugosz (Monsignor) on Sep 05, 2001 at 02:39 UTC | |
|
Re: Re: Checking whether a $var is a number
by dga (Hermit) on Sep 05, 2001 at 22:59 UTC |