Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Equivalent to Integer?

by screamingeagle (Curate)
on Feb 11, 2002 at 07:18 UTC ( #144592=note: print w/replies, xml ) Need Help??

in reply to Equivalent to Integer?

quoting from PerlFaq4, here are various ways to check if a scalar variable is a number/whole/integer/float :
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" } if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "a C float" }
(Take your pick)... and if u want to use a negated regular expression, use the
syntax instead of the

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://144592]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2016-10-23 14:35 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.