in reply to Number?

I think using 'int' does a good job of this:
print "is number" if int($test);
If $test = '5.55555' it works, but if $test = 'howdy', it doesn't.

-mark

Replies are listed 'Best First'.
RE: markjugg-- using int to test numberness
by extremely (Priest) on Oct 25, 2000 at 08:44 UTC
    Um, no... this is bad...
    perl -e 'print "yikes\n" if int("1upmanship")' perl -e 'print "Zero is a number.\n" if int("0")'

    prints yikes! but not the "Zero..." line. int() doens't test a number it truncates it to integer form. And since the number 0 is false the second line doesn't work. Treating a string that starts with numeral as a number causes perl to whack off the text and use the number. OUCH!

    --
    $you = new YOU;
    honk() if $you->love(perl)