home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7490 < prev    next >
Encoding:
Text File  |  1992-12-17  |  2.0 KB  |  51 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!hamblin.math.byu.edu!news.byu.edu!news.mtholyoke.edu!jbotz
  3. From: jbotz@mtholyoke.edu (Jurgen Botz)
  4. Subject: Perl & manipulating large texts
  5. Message-ID: <BzF1Cn.M1t@mtholyoke.edu>
  6. Sender: news@mtholyoke.edu (USENET News System)
  7. Organization: Mount Holyoke College
  8. Date: Thu, 17 Dec 1992 18:14:47 GMT
  9. Lines: 40
  10.  
  11. I was recently playing with some parsing stuff in the process of
  12. trying to parse a very large (> 1MB) text file, and I found myself
  13. unable to determine how to deal with the text efficiently.  I'd like
  14. some input on this... here are the parameters of the problem:
  15.  
  16. - I can't just read line by line because I might have to backtrack.
  17.  
  18. - I need to be able to address individual character positions, not
  19.   just lines.
  20.  
  21. - I need to be able to use regexps to match chunks of text from the
  22.   beginning (possibly crossing line-boundaries) and then use the
  23.   matched chunk for something and then repeat with the text beyond
  24.   what was matched.  (i.e. bite off chunks from the beginning.)
  25.  
  26. A powerful idiom that makes the lexical part very easy is being able
  27. to use regular expressions and the get the text that matched from
  28. $& and the rest of the text for the next pass from $'.  However,
  29. it seems to me that sucking a > 1MB file into a scalar and then
  30. iterating with something like...
  31.  
  32.   $* = 1;
  33.   while (/$pat/) {
  34.     $match = $&;
  35.     $_ = $_;
  36.     &do_something_with($match);
  37.     $pat = &next_pat();
  38.    }
  39.  
  40. must be prohibitively inefficient.  I guess essentially the problem is
  41. that I can't find a way to use a C-like idiom with pointers into
  42. the text.  Maybe Perl 5 references will take care of this?  I noticed
  43. that "substr" returns an L-value, but couldn't find any way to take
  44. advantage of that fact.
  45.  
  46. --
  47. Jurgen Botz                  |   Internet: JBotz@mtholyoke.edu
  48. Academic Systems Consultant  |     Bitnet: JBotz@mhc.bitnet
  49. Mount Holyoke College        |      Voice: (US) 413-538-2375 (daytime)
  50. South Hadley, MA, USA        | Snail Mail: J. Botz, 01075-0629
  51.