Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!comp.vuw.ac.nz!ajv From: Andrew.Vignaux@comp.vuw.ac.nz (Andrew Vignaux) Newsgroups: comp.lang.perl Subject: Re: Perl Neophyte Needs Help Message-ID: <1990Jun27.101219.11357@comp.vuw.ac.nz> Date: 27 Jun 90 10:12:19 GMT References: <8504@jpl-devvax.JPL.NASA.GOV> Sender: news@comp.vuw.ac.nz (News Admin) Organization: Comp Sci, Victoria University, Wellington, New Zealand. Lines: 45 In article <8504@jpl-devvax.JPL.NASA.GOV>, lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: > The only other tricky thing we might do here is to put the whole loop > inside an eval so that the pattern gets compiled before the optimizer > runs. The eval is just using the here-is syntax to quote the evaluated > bit of program. > [...] > $pattern = shift; # get first argument > [...] > eval <<"EOF"; # to avoid recompile pattern each time > while (<>) { > print if /$pattern/; > } > EOF I've always been a little wary about using the "eval-the-loop" trick because it will probably mean that the whole perl compiler/interpreter will get sucked into my executable when (not if :-) a "perl to C translator" comes along. [Note: ispell thinks that "eval" is "evil" -- so it's not just my opinion :-] Of course this doesn't stop me using it. I think the only time *I* every really want to do this is for building the regexp test(s) based on the script arguments i.e. a grep-like script (just like this example). Does/could perl notice that $pattern is invariant in the original program and arrange to compile the regexp only once? Comments? Andrew -- Domain address: Andrew.Vignaux@comp.vuw.ac.nz PS: While I was looking at the Wishlist, I noticed that "built-in cpp" was there. Well, I'd be really keen on at least "#include". I've also been worried about the distinction between "#include" and "do". I often want to include a subroutine in multiple scripts: I'd rather not have the longer cpp startup time when I'm interpreting the script, or the runtime compile of "do" for the compiled script. Should I be using the pat.SH / package.pl (from dist) approach? PPS: ispell suggests that "perl" is "peril", but we already knew that :-)