Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Checking whether a value is numeric or not

by Krambambuli (Deacon)
on Nov 27, 2008 at 08:08 UTC ( #726333=note: print w/ replies, xml ) Need Help??


in reply to Checking whether a value is numeric or not

Well, what exactly do you define as being a "numeric value" ?

7.89e-200 ? 0xabc ? They both are numeric values...

If you think about a string of exclusive decimal digits, you might want to rewrite your test as

if($blk !~ /^[\d]+$/) {print "Invalid value"};
or so.

Krambambuli
---


Comment on Re: Checking whether a value is numeric or not
Download Code
Replies are listed 'Best First'.
Re^2: Checking whether a value is numeric or not
by gwadej (Chaplain) on Nov 28, 2008 at 14:36 UTC

    For this particular case, I would probably use:

    if($blk =~ /\D/) { print "Invalid value";}

    For some reason, it seems clearer to me.

    G. Wade

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-29 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls