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

Re: _ in a number within quotes

by linuxer (Deacon)
on Apr 19, 2009 at 16:40 UTC ( #758587=note: print w/ replies, xml ) Need Help??


in reply to _ in a number within quotes

Also I would have thought that the numeric operator would have considered it as a string (in which case $a should have been 0+1) and evaluated to 1 or as a number 1334 and evaluated to 1335;

$a with its content "1_1334" is not treated as 0 in numeric context. Perl checks the value and sees that the string starts with a number. So it takes and uses that number in numeric context. That's why your $a + 1 results in a 1 + 1 =2 instead of a 0 + 1 = 1.

Other example:

perl -wle '$a = "7__hello"; print "yes" if $a == 7;' Argument "7__hallo" isn't numeric in numeric eq (==) at -e line 1. yes

But beware: $a = "1_334"; is different to $a = 1_334;. While the first one is a string, which is treated as 1 in numeric context, the second one is a fully valid numeric value 1334. The underscore (_) can be inserted to improve readability.


Comment on Re: _ in a number within quotes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-08-22 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (145 votes), past polls