Bryan R Harris wrote:
This is unintuitive:
perl -e 'print "> "; while(<>) {print(( eval $_ )[-1], "\n> ")}'
... then enter 2*012. It prints "20". 2*12 is obviously 24, but perl's
interpreting that "012" as octal. We sometimes have our numbers zero padded
to make the columns line up, they're not octal.
Is there any way to keep perl's eval from interpreting numbers starting with
"0" as octal?
I tried to regex them out but that regex is tricky since I'm writing a
custom calculator, and I have no idea what the user might enter.
$ perl -lne 'BEGIN{$\="\n> ";print}s/(\d+)/0+$1/eg;print+(eval)[-1]'
> 2*012
24
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/