Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cunixf.cc.columbia.edu!ben From: ben@cunixf.cc.columbia.edu (Ben Fried) Newsgroups: comp.lang.perl Subject: Re: Why is this so slow? Message-ID: <1990Dec10.022814.5349@cunixf.cc.columbia.edu> Date: 10 Dec 90 02:28:14 GMT References: <1990Dec7.212127.8161@uvaarpa.Virginia.EDU> Organization: Columbia University Center for Computing Activities Lines: 34 In article <1990Dec7.212127.8161@uvaarpa.Virginia.EDU> Dale Worley writes: > From: merlyn@iwarp.intel.com (Randal Schwartz) > > $lines_per_page = 66; $max_pages = 100; # you forgot this > while (<>) { > $lineno++; > $pageno++, $lineno = 0 if /\f/ || ($lineno >= $lines_per_page); > die "Aborted at page $pageno\n" if $pageno >= $max_pages; > print; > } > > Well, to start with, if there are two form-feeds in one line, $pageno > will only get incremented by 1. > > I may be wrong, but to find out the number of times a regexp matches a > string, you have to write an explicit loop. This is a good point - neither Randal's nor Larry's posted code handles this case. Larry's code for non-plaintext files works just great: in those cases, the _only_ way that the printer can reach end of page is by a \f or an \033\f, depending on mode; his idea of setting $/ to \f (and in the second case matching against /\033\f$/) works great. This made me wish that perl had some operator for determining the count of matches of a pattern; is that something that sounds generally useful? > Dale Worley Compass, Inc. worley@compass.com Ben -- Benjamin Fried ben@cunixf.cc.columbia.edu rutgers!columbia!ben