in reply to comparing output to check if is an integer or float

Check perlfaq4, under Data:Misc, the second faq is how can you determine whether a string is an integer or float. As you said that you are new, I copied a piece from the answer, and pasted it here, hope it helps.

It basically said two things: (As you said the entity you want to check is returned from some math function, maybe I can assume the return is a number. If that is true, you can just check whether int($num) == $num.)
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
    The OP didnt actually say if the number in question was coming from an input stream of some sort or an internally generated one. If it was internally generated one then
    if (int($num)==$num) {
    would seem to be a little better.

    --- demerphq
    my friends call me, usually because I'm late....