Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!olivea!tymix!tardis!udwarf.tymnet.com!carl From: carl@udwarf.tymnet.com (Carl Baltrunas & Cherie Marinelli 0.1.9) Newsgroups: comp.lang.perl Subject: Re: Why is this so slow? Message-ID: <0B030501.O4CUJJ@udwarf.tymnet.com> Date: 8 Dec 90 05:27:19 GMT Reply-To: carl%udwarf@tardis.tymnet.com Organization: Catalyst Art Lines: 54 X-Mailer: uAccess - Mac Release: 0.1.9 In article <1990Dec6.194412.9132@cunixf.cc.columbia.edu>, ben@cunixf.cc.columbia.edu (Ben Fried) writes: > > I've written a filter in perl to do printer page counting for DEC ln03 > printers. Right now it seems to be working fine, but it runs abysmally > slowly. The vast majority of time is taken up in the following loop: > > [perl script deleted] > > All that really matters is that I be able to count the > number of pages on the input stream, and be able to break out of the > loop after either (a) EOF on stdin, or (b) $pageno == $max_pages, > whichever comes first. > ...more stuff deleted... > Ben > -- > Benjamin Fried > ben@cunixf.cc.columbia.edu rutgers!columbia!ben I know that Ben didn't mention this, and so it wasn't in Randal's or Larry's responses, so I thought that I'd bring it up. (I've had to write filters on non-unix machines to create microfiche-able output, so I've had to do this). What about line length? (Page width or whatever you want to call it) ..and what about line wrap on long lines. Some print filters do these things for you, and this changes the the characteristics of the output from straight \n and \f counting. So, can you tell perl that while reading input lines to break lines at the point you want to make it wrap, or do you have to use something like the following modifications to randal's response: $lines_per_page = 66; $max_pages = 100; # you forgot this while (<>) { $lineno += ( (length($_) + $line_width - 1) / $line_width ); $pageno += ( $lineno + $lines_per_page ) / $lines_per_page, \ $lineno = 0 if /\f/; $pageno++, $lineno -= $lines_per_page if ($lineno >= $lines_per_page); die "Aborted at page $pageno\n" if $pageno >= $max_pages; print; } And one thing I left out... what to do about \t's (TABS) in text, since they push the line width quite a bit depending on position. (I won't mention all those [which font?] [what about kerning?] word processing things. They must require handling each byte. :-) PS. I guess an array of flags and point sizes could be built first based on the font used and a state machine that uses the byte value to lookup the width of each character and flags to add kerning offsets and can we break the line here... would make a pretty fast way of processing it. Randal, can this be done easily in perl? How about a 1 liner? -Carl Carl A Baltrunas - Catalyst Art, Cherie Marinelli - Bijoux {sumex, apple}!oliveb!tymix!tardis!udwarf!{carl or cherie} {carl or cherie}%udwarf@tardis.tymnet.com {carl or cherie}@udwarf.tymnet.com