in reply to Checking whether a $var is a number

The canonical answer to IsNan is found here: http://www.cpan.org/doc/FMTEYEWTK/is_numeric.html

To Quote:

The special IEEE notions of Infinity and NaN (not a number) will be pr +operly honored: $n = 'NaN'; print 2 * $n; NaN print 10 * $n NaN print 1 + NaN NaN $i = 'Infinity' print 1 + $i Infinity print $i * $i Infinity print $i - $i NaN print 'Infinity' < 0 0 print 'Infinity' > 0 1

hsm

Edit by tye to change very wide BLOCKQUOTE+PRE to CODE

Replies are listed 'Best First'.
Re: Re: Checking whether a $var is a number
by blakem (Monsignor) on Sep 06, 2001 at 02:21 UTC
    Interesting, it looks like this works, but they return 'inf' and 'nan' instead of the longer capitalized versions above.
    % perl -le "print 1 + 'NaN'" nan % perl -le "print 1 + 'Infinity'" inf

    -Blake