Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!think!mintaka!ogicse!orstcs!sapphire!pvo From: pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) Newsgroups: comp.lang.perl Subject: Re: variable is numeric? Message-ID: <16943@orstcs.CS.ORST.EDU> Date: 16 Mar 90 23:14:34 GMT References: <16918@orstcs.CS.ORST.EDU> <7443@jpl-devvax.JPL.NASA.GOV> Sender: usenet@orstcs.CS.ORST.EDU Reply-To: pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) Organization: Coastal Imaging Lab, Oregon State University, Corvallis, OR Lines: 64 In article <7443@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >In article <16918@orstcs.CS.ORST.EDU> pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) writes: >: What is the Canonical Test of whether a variable is numeric? > >I'm not sure what you mean by that. Hmm. Looks like I tried to save too much bandwidth. :-) A lot of survey data comes through this lab. Data from different institutions using different instruments in different formats. Some is in feet that needs converting to meters. Almost invariably, the data needing conversion appear as a triplet of numbers. What a great job for perl! My perl script to convert surveyed feet to surveyed meters justs looks for a line w/ 3 consecutive numbers and multiplies all such triplets by 0.3048006. BUT IT'S UGLY: ----------------------------------------------------------------------- #!/usr/local/bin/perl # # ft2m_any.perl # 27 feb 90 # Paul V. O'Neill -- Coastal Imaging Lab, OSU, Corvallis, OR 97331 # # feet to meters convertion on lines consisting of 3 consecutive numbers # leave other lines alone # format STDOUT = @<<<<<< @<<<<<< @<<<<<<< $meters[0], $meters[1], $meters[2] . while (<>) { # get a line at a time $save = $_; @feet = /([0123456789.]*)\s*([0123456789.]*)\s*([0123456789.]*)\s*/; if($feet[2]) { @meters = grep($_ *= .304800609601, @feet ); write; } else { print $save; } } -------------------------------------------------------------- [0123456789.] seems a gross way to identify a number. And "10.33.9" would pass the test. If perl knows that a variable is numeric (automagical increment writeup) why can't I know? I'd much prefer to split the current line and do some cute, canonical test on each member of @_ for "numberness." Thanks. Paul O'Neill pvo@oce.orst.edu Coastal Imaging Lab OSU--Oceanography Corvallis, OR 97331 503-737-3251