in reply to comparing output to check if is an integer or float
Assuming that you don't care about IEEE notations like ``NaN'' or ``In +finity'', you probably just want to use a regular expression. if (/\D/) { print "has nondigits\n" } if (/^\d+$/) { print "is a whole number\n" } if (/^-?\d+$/) { print "is an integer\n" } if (/^[+-]?\d+$/) { print "is a +/- integer\n" } if (/^-?\d+\.?\d*$/) { print "is a real number\n" } if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "is a decimal number\n" +} if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "a C float\n" }You can also use the Da +ta::Types module on the CPAN, which exports functions that validate d +ata types using these and other
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: comparing output to check if is an integer or float
by demerphq (Chancellor) on Dec 08, 2002 at 00:25 UTC |