Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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]
[karlgoethebier]: Cojones! We need cojones!
[karlgoethebier]: Ouch! Permissions! We need permissions!
[BarApp]: I can not use modules. I gain temporary access and still can not use modules.
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-06-29 16:45 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.