in reply to Re^2: Leading Zeros confound eval() ?
in thread Leading Zeros confound eval() ?

misterperl:

In your original code, you have:

my $x = "016";

If you leave the quotes out, it would be treated as an octal number. So in the perl source code 016 is an octal number. But when perl converts a string to a number, it doesn't perform any octal, binary or hexadecimal conversions. So this bit of code would treat it as a normal decimal number:

$ perl -e 'my $x="016"+1; print $x,"\n"' 17 $

When you use eval, you can treat a string as a bit of perl source code, so it will be treated as an octal number:

$ perl -e 'my $x=eval "016"; print $x,"\n"' 14 $

Update: I should've read the rest of the thread before replying, Anonymonk already said this.

...roboticus

When your only tool is a hammer, all problems look like your thumb.