Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Checking whether a value is numeric or not

by Krambambuli (Curate)
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.


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?

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

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

    Results (309 votes). Check out past polls.