On Fri, Feb 19, 2010 at 10:34 PM, Bryan R Harris <bryan_r_har...@raytheon.com> wrote: > > >> >>> Is there any way to keep perl's eval from interpreting numbers starting >>> with >>> "0" as octal? >> >> Stringify them ? >> 2 * '012' is 24. > > Manually? > > We could have thousands of them. How do I stringify them when they may > potentially be in the middle of an expression? eg. 75+32*(15+052/3) > > - Bryan > >
Step back a second. You said the data is zero-padded to make your columns line up, but there are no columns in your input. That means there is some intermediate step where the the columnar data is being compiled into the expressions you want to evaluate. The simplest method--if you have access to it--would be to strip the leading zeros from the initial input, rather than trying to parse the expression prior to evaluating it. Assuming the first time you see the data is when you eval it, though, something like the following should come pretty close to meeting your needs: perl -e 'print "> "; while(<>) {chomp; s/(\D)(0\d*)/$1 eq "." ? $1."$2" : $1.(0+$2)/ge; print "$_\n"; print(( eval $_ ), "\n> ")}' That is, search the string for every instance of a non-digit, followed by zero, followed by zero or more digits. If the non-digit is a ".", return the non-digit and the string of digits as a string. If the the non-digit is something else, return the 0 + the non-digit, interpreted as base 10. That won't be as robust as constructing your own parser as suggested above, but as long as your input is composed of numbers and operators as you expect, it should be a start. HTH, -- jay -- -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/