Tom Allison wrote:
> 
> Also, is there any reason NOT to end the regex with /o to improve
> performance?

perldoc -q '/o'

Found in /usr/lib/perl5/5.8.6/pod/perlfaq6.pod
       What is "/o" really for?

       Using a variable in a regular expression match forces a
       re‐evaluation (and perhaps recompilation) each time the regular
       expression is encountered.  The "/o" modifier locks in the regex
       the first time it’s used.  This always happens in a constant
       regular expression, and in fact, the pattern was compiled into
       the internal format at the same time your entire program was.

       Use of "/o" is irrelevant unless variable interpolation is used
       in the pattern, and if so, the regex engine will neither know nor
       care whether the variables change after the pattern is evaluated
       the very first time.

       "/o" is often used to gain an extra measure of efficiency by not
       performing subsequent evaluations when you know it won’t matter
       (because you know the variables won’t change), or more rarely,
       when you don’t want the regex to notice if they do.

       For example, here’s a "paragrep" program:

           $/ = ’’;  # paragraph mode
           $pat = shift;
           while (<>) {
               print if /$pat/o;
           }



John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to