Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Why is this so slow? Message-ID: <1990Dec6.205447.13500@iwarp.intel.com> Date: 6 Dec 90 20:54:47 GMT References: <1990Dec6.194412.9132@cunixf.cc.columbia.edu> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 63 In-Reply-To: ben@cunixf.cc.columbia.edu (Ben Fried) In article <1990Dec6.194412.9132@cunixf.cc.columbia.edu>, ben@cunixf (Ben Fried) writes: | mainloop: | while(read(STDIN, $_, 2048)) { | foreach $i ($[..length($_)) { | $num_to_print = $i; | $oc=$c; | $c = substr($_, $i, 1); | if ($tektronixmode) { | if (($c eq "\f") && ($oc eq "\033")) { | $pageno++; | } | } else { | if ($ascii_mode) { | if ($c eq "\n") { | $lineno++; | if ($lineno == $lines_per_page) { | $lineno = 0; | $pageno++; | } | } | } else { | if ($c eq "\f") { | $lineno = 0; | $pageno++; | } | } | } | | if ($pageno >= $max_pages) { | $debug && print STDERR "aborted at page $pageno\n"; | print STDOUT substr($_, $[, $num_to_print); | last mainloop; | } | | } | | print STDOUT; | } 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 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. :-) print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/ Brought to you by Super Global Mega Corp .com