Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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
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 romping around the Monastery: (5)
As of 2014-09-19 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls