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

Re: _ in a number within quotes

by linuxer (Curate)
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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2015-10-04 17:19 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (103 votes), past polls