home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 8047 < prev    next >
Encoding:
Text File  |  1993-01-29  |  1.4 KB  |  44 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!spillman!tye
  3. From: tye@spillman.uucp (E. Tye McQueen)
  4. Subject: Re: Leftmost longest?
  5. Message-ID: <1993Jan27.171211.32439@spillman.uucp>
  6. Date: Wed, 27 Jan 1993 17:12:11 GMT
  7. References: <1993Jan26.131142.6158@infodev.cam.ac.uk>
  8. Organization: Spillman Data Systems
  9. Lines: 33
  10.  
  11. seb1005@mbfs.bio.cam.ac.uk (Steven Brenner) writes:
  12. )
  13. )   ($mynumber) = /R[- \n]+VALUE.*(0.\d+)/;
  14. )
  15. )   but where the .* in the middle matches the shortest string to make
  16. )the whole pattern match rather than the longest.
  17.  
  18. Since the pattern after ".*" always starts with "0", you can do:
  19.  
  20.     ($mynumber) = /R[- \n]+VALUE[^0]*(0.\d+)/;
  21.  
  22. Though it won't work for  "R - VALUE 0 0.5", but I doubt that will
  23. be a problem.  You could elaborate on this to fix it and other problems
  24. but it probably wouldn't be worth the loss of readability/speed.
  25. Something silly like (which probably doesn't work):
  26.  
  27.     ($mynumber) = /R[- \n]+VALUE([^0]*(0[^.]|0.\D))*(0.\d+)/;
  28.  
  29.  
  30. )        if (($s) = /(R[- \n]+VALUE)/) {
  31. )          $i = index ($_,$s);
  32.  
  33.     $i= length($`);
  34.  
  35. might be better (and may be off by one or so).
  36.  
  37. )          ($mynumber) = (substr($r3,$i) =~ /(0.\d+)/);
  38. )        }
  39.  
  40.  tye@spillman.com                         Tye McQueen, E.
  41. ----------------------------------------------------------
  42.  Nothing is obvious unless you are overlooking something. 
  43. ----------------------------------------------------------
  44.