Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!apple!agate!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: fast grep? Message-ID: <1990Oct17.044839.21709@iwarp.intel.com> Date: 17 Oct 90 04:48:39 GMT References: <1990Oct15.211219.8543@wrl.dec.com> <107211@convex.convex.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 44 In-Reply-To: tchrist@convex.COM (Tom Christiansen) In article <107211@convex.convex.com>, tchrist@convex (Tom Christiansen) writes: | I still can't get it sufficently close to gnugrep to justify not running a | system on gnugrep, but even so, there's nothing truly wrong with that. I | don't think Larry would have made popens and `foo` and system() so easy to | get at if he didn't want you do use them. Note that perl DOES beat | everything except for gnugrep. One of these days, I've got to see whether | I can't vectorize any of the regexp stuff in perl... Tom, go back and rerun your test with some slightly-more-optimal (I hope) Perl code: ################################################## #!/usr/bin/perl # @ARGV = ('/usr/dict/words'); # for testing undef $/; # enable maximal slurp mode $* = 1; # ^$ work in searches with newlines while (<>) { s/string/&cheat($`,$&,$')/eg; } sub cheat { local($left,$center,$right) = @_; print substr($left,rindex($left,"\n")+1,99999), $center, substr($right,0,index($right,"\n")+1); $center; } ################################################## I think you were getting beat up on how often you went around the while loop. This code more closely matches what bmgrep is doing inside. (Yes, I actually tested this code for a change. :-) print "Just another Perl hacker," # with theoretically enough time to write a good JAPH now, but still not doing it.... :-) -- /=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: "Welcome to Portland, Oregon, home of the California Raisins!"=/