From the perl cookbook section 2.1, with my own reformatting and comments:
sub isThisADecimalNumber {
my ($string) = @_;
return $string =~ /^\s*
-? # negative sign - optional
(?:
\d+ # digits
(?:\.\d*)? # and an optional decimal and
+maybe more digits
| # OR
\.\d+ # a decimal and some digits
)
\s*$/x;
}
I have not totally isolated when it does not work yet. I am testing for a floating point number to separate from both booleans and strings all of which are values in a hash.
I just had deja vu writing this....yet no recollection of doing this in a past life.
For your purposes, are the integers not floats? I can't think of any case where the int($n) != $n test wouldn't work. Or would it be a float if it were '0.0' (for example)?
Though you haven't isolated when it doesn't work, can you give any example for which it doesn't work?
Caution: Contents may have been coded under pressure.