Hi Bryan! 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. 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 (Also see the replies). Regards, Shlomi Fish > > 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. > > TIA. > > Bryan -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Interview with Ben Collins-Sussman - http://shlom.in/sussman Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/