Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Checking whether a $var is a number

by wog (Curate)
on Sep 05, 2001 at 00:15 UTC ( [id://110146]=note: print w/replies, xml ) Need Help??


in reply to Checking whether a $var is a number

Unfortunately perl does not have any built-in functions to do just this. One way you could check it is by seeing if perl warns "... is not numeric ..." when you try to do something with a value:

# numeric -- returns true if arg. is numeric sub numeric { my $value = shift; my $result = 1; local $^W = 1; # turn warnings on if they aren't already. local $SIG{__WARN__} = sub { $result = 0 }; # if we get a warning make $result false $value += 0; return $result; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found