Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://758587]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-04-28 09:01 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (519 votes). Check out past polls.