Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: How to check if a scalar value is numeric or string?

by JavaFan (Canon)
on Aug 27, 2009 at 14:58 UTC ( [id://791671]=note: print w/replies, xml ) Need Help??


in reply to Re: How to check if a scalar value is numeric or string?
in thread How to check if a scalar value is numeric or string?

Generally, yes. In a few cases, there's a difference. Binary bit operators, for instance.
say "12" | "34"; # 36 say 12 | 34; # 46
And you might think the following code won't give you a divide by zero error:
if ($num && $num =~ /^[0-9]+$/) {say 1/$num}
but it will if $num eq '00'.

Devel::Peek is a tool that can tell you whether scalar holds a numeric value or not (look for the IV and NV flags).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found