Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by LanX (Chancellor)
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

Replies are listed 'Best First'.
Re^3: What is the correct definition of False and Null in Perl? [non-decimal strings]
by flexvault (Monsignor) 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?
[Lady_Aleena]: Would you use a module that is almost 150 characters to type with the use and importing all subroutines?
[LanX]: use module :all ?
[Lady_Aleena]: Lax, that would take it down to a little less than 100 characters. The module name is nearly 80 characters long.
Lady_Aleena has fumble fingers today.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2017-05-24 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?