> On Saturday 20 Feb 2010 04:53:18 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?
>
> No, there isn't. But why are you writing a custom calculator using eval? A
> user may enter something like << system('rm -fr $HOME'); >> and get his home
> directory deleted. And other stuff like that.
Because this isn't a web app, it's a script on a shared drive. If the users
wanted to do that, they could just type that command at the terminal.
> If you're interested in writing a calculator or a different interpreter the
> look at parser-generator modules:
>
> http://www.nntp.perl.org/group/perl.module-authors/2009/09/msg7844.html
Wow, I'm not even sure how that discussion connects to my situation -- I
don't recognize enough of the words to make the connection (this is a
beginners list, remember? =)
- Bryan
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/