home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6947 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  3.5 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Partial RegExp's
  5. Message-ID: <1992Nov12.003038.18617@netlabs.com>
  6. Date: 12 Nov 92 00:30:38 GMT
  7. Article-I.D.: netlabs.1992Nov12.003038.18617
  8. References: <BxGFIy.LuA@news.cso.uiuc.edu>
  9. Sender: news@netlabs.com
  10. Organization: NetLabs, Inc.
  11. Lines: 58
  12. Nntp-Posting-Host: scalpel.netlabs.com
  13.  
  14. In article <BxGFIy.LuA@news.cso.uiuc.edu> chappell@math.uiuc.edu (Glenn Chappell) writes:
  15. : Here's a question I've been pondering for a few weeks:
  16. : Inherent in the design of Perl seems to be the idea that you always have
  17. : enough space in memory for the entirety of any file you'd ever want to
  18. : work on. But what if you don't? How does one do wonderful things like
  19. : "split" and various pattern matches & such on files that are just too big?
  20. : Well, if there's already a standard, ok-I'll-spell-it-all-out-for-a-
  21. : neophyte-like-you-but-next-time-read-the-book-okay answer to this
  22. : question, I'd like to hear it. If, not, an idea:
  23. : Of course, the way you deal with huge files is to read them in chunks.
  24. : The problem with that is that you miss a pattern match that starts on
  25. : one chunk and ends on another.
  26. : Currently, the result of an attempt at a pattern match gives one of two
  27. : responses: "Got a match" or "Didn't get a match". What if there were a
  28. : way to tell the pattern matcher that some patterns may extend off the
  29. : end of the currently available text, and we gave the matcher the ability
  30. : to give two other reponses: "Got a partial match, and if you give me
  31. : more data, I may get a match" and "Got a match, which may turn into a
  32. : bigger match if you give me more data". The matcher would also return
  33. : the place at which the partial match began.
  34. : Now, from what I know of pattern matching, it seems to me that this would
  35. : be an easy modification to do. The question, then, is whether it would
  36. : be worthwhile. So, does anyone think so? Or is it just me?
  37.  
  38. The main problem is the semantics of *, + and {}.  Currently these want
  39. to match the LONGEST possible string.  Some patterns would have to
  40. slurp in the entire file anyway.
  41.  
  42. This is one of the reasons that Mark and I have been talking about
  43. variants of *, + and {} that would match the shortest string possible.
  44. Currently there are only two ways to do first-match rather than last-match:
  45. 1) have the thing you're looking for be the first thing in a pattern, or
  46. 2) carefully write the intermediate stuff to exclude the pattern you're
  47. looking for.  Both of these approaches leave something to be desired.
  48.  
  49. A thing that might help with option 1 is if we attached the state of
  50. m//g searches to the searched string rather than to the pattern
  51. itself.  This would let you switch from one pattern to another in mid
  52. search.  One could then do tokenizing without s///, for instance.  Of
  53. course, that doesn't help the slurp-in-more-file-if-you-run-out problem.
  54.  
  55. I don't see any theoretical problems with regular expression operators
  56. that backtrack by attempting to match more rather than less.  There's
  57. certainly no problem with oscillation, since any given operator always
  58. progresses in the same direction.
  59.  
  60. As for the feature in question, it's just one of those things where you
  61. try to figure out the most general (and practical) way to do it, then
  62. think about whether you want to do it at all, and then maybe find time
  63. to do it.  None of these is a trivial undertaking.  Language design is
  64. not a haphazard activity, appearances notwithstanding.  :-)
  65.  
  66. Larry
  67.