Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!helios.ee.lbl.gov!pasteur!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Converting a string to a number Message-ID: <1990Jul14.164603.7498@iwarp.intel.com> Date: 14 Jul 90 16:46:03 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 37 X-Local-Date: 14 Jul 90 09:46:03 PDT In-Reply-To: pablo@mrspoc.Transact.COM (Pablo Sanchez) In article , pablo@mrspoc (Pablo Sanchez) writes: | I'm on a XENIX 386 (2.3.2) running Perl 3.0 pl 18. My code is doing | something very simple. I'm reading in a text line that has a number assigned | to it (e.g. "ROW_ORIGIN 8") and I need to get the number portion out. Once I | get the number portion out, I wish to convert this to a number. I thought I | could do it one way, but have had to work around it... | | Here's the first way I thought I could do it: | | $last_screen_line[0] =+ 0 ; # convert to a number Well, first, "=+" is not an operator. But += doesn't work either, because the string's value is 0. Extract the number instead with a substitution. $last_screen_line[0] = "ROW_ORIGIN 8"; $last_screen_line[0] =~ s/^\D+//; # eliminate all leading non-digits. # $last_screen_line[0] =~ s/^\D*(\d+).*//; # if imbedded instead print "value is $last_screen_line[0], and 3+that is ", 3+$last_screen_line[0]; | | But on my system, this always prints out zero. So instead I had to do the | following: | | $last_screen_line[0] = $last_screen_line[0] + 0 ; This seems like it would always give zero... if I read the spec properly. print "Just another non-zero Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/