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

Re^2: What is the correct definition of False and Null in Perl? [non-decimal strings]

by LanX (Canon)
on Oct 08, 2011 at 12:05 UTC ( #930334=note: print w/ replies, xml ) Need Help??


in reply to Re: What is the correct definition of False and Null in Perl?
in thread What is the correct definition of False and Null in Perl?

> Adding 0 to the variable makes Perl explicitly convert the string to a number:

However there is still confusion with some number formats like hexadecimal, because Perl only converts strings which represent integers or floats as decimals! (see perlnumber).

just run

$a="0x10"; ++$a;

and in Perl $a is now 1 in JS it's 17!

Cheers Rolf

UPDATE: OTOH JS obviously can't handle octals the same way:

repl> $a=010; ++$a 9 repl> $a="010"; ++$a 11


Comment on Re^2: What is the correct definition of False and Null in Perl? [non-decimal strings]
Select or Download Code
Re^3: What is the correct definition of False and Null in Perl? [non-decimal strings]
by flexvault (Parson) on Oct 09, 2011 at 13:20 UTC

    I redid your code, dropping the quotes as:

    $a=0x10; ++$a; print "$a\n";

    And the result was 17 (perl5.10.1 and perl5.12.2), which I think was what you wanted.

    P.S. I am amazed how many good comments have come from this question and the PM answers.

    Thank you

    "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-10-25 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls