Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: numeric from string Message-ID: <7347@jpl-devvax.JPL.NASA.GOV> Date: 8 Mar 90 19:01:22 GMT References: <13537@cbnewsd.ATT.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 36 In article <13537@cbnewsd.ATT.COM> weiss@cbnewsd.ATT.COM (edward.j.weiss,ihp,) writes: : To start out I'm using Release 3.0 PatchLevel 12. : : Try out: : : perl -e '$m="0777"; $n = $m + 1; print $n,"\n";' : : What should the answer be? : : I would guess that 0777 would be converted to a number by : using 8 as a base, but it doesn't. Base 10 is used. : MisFeature? No, there are too many strings that come in from the outside world that have leading zeros and yet want to be decimal. Base conversion only happens where you have control of it--in the tokener, and by explicit use of oct() and hex(). Doing it the other way would cause many more problems than it would solve. : I found trying to use chmod like: : : $mode=<>; chop; chmod($mode,$file); To stretch the example of oct() from the manual: $mode = <>; $mode = oct($mode) if $mode =~ /^0/; chmod($mode, $file); (It's unnecessary to do the chop, since ordinary numeric conversion will ignore it.) If you wanted to always interpret it as octal even if they didn't input the leading zero, you would just drop the if modifier. Larry