Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!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: <1990Dec6.220913.11567@cunixf.cc.columbia.edu> Date: 6 Dec 90 22:09:13 GMT References: <1990Dec6.194412.9132@cunixf.cc.columbia.edu> <1990Dec6.205447.13500@iwarp.intel.com> Organization: Columbia University Center for Computing Activities Lines: 53 In <1990Dec6.205447.13500@iwarp.intel.com> Randal writes: [ My source code ] > Hmm. That's probably the right way to do it in some other language > besides Perl. (It smells vaguely BASIC-like, or maybe C-like.) > > Anyway, as a first cut, I'd do something like: > > $lines_per_page = 66; $max_pages = 100; # you forgot this They're set elsewhere in the program; sorry for not including that. > while (<>) { > $lineno++; > $pageno++, $lineno = 0 if /\f/ || ($lineno >= $lines_per_page); > die "Aborted at page $pageno\n" if $pageno >= $max_pages; > print; > } > > Yes? Maybe? OK, so I didn't add the tek vs. ascii mode, but that'd > only make it one line longer. :-) > > I think you'll find this runs a teensy-tiny bit faster. :-) I failed to adequately explain my problem: only in about 1/3 of the cases are there newlines in the input, in the rest they may not appear at all, or if they do they do not delimit lines, but appear as binary data. In those cases (plain ascii files), Randal's code is 100% correct. However, in the remainder of the cases, I cannot depend on newlines or any other line (or record, or whatever you want to call it) delimiter being present to allow easy use of the while (<>) construct. In fact, one might see a sequence sort of like: \n\f\n\n\n\nxxxxweriuweru925349853495\033\fasdfsdfasdf\033\f9r8\f3495\fasasf\n In this case, the \n's and plain \f's should be ignored - they're data, not line separators - pages are separated by \033\f, and plain \f's are just data, and max_pages might very well be reached after the first \033\f combination there. In other cases, though, \f by itself is a page-eject; it depends on what mode the printer is in. > print "Just another Perl hacker," > -- Whatever... Ben -- Benjamin Fried ben@cunixf.cc.columbia.edu rutgers!columbia!ben Brought to you by Super Global Mega Corp .com