in reply to Re: Regex: same code works and fails, why?
in thread Regex: same code works and fails, why?

From 'man perlop':
If you want such a pattern to be compiled only once, add a "/o" after the trailing delimiter. This avoids expensive run-time recompilations, and is useful when the value you are interpolating won't change over the life of the script.

Same thing in camel book (3rd ed.) p.148.
  • Comment on Re:^4 Regex: same code works and fails, why?

Replies are listed 'Best First'.
Re: Re:^4 Regex: same code works and fails, why?
by duff (Parson) on Jan 07, 2004 at 16:45 UTC

    You left out some important context. The full text is

    PATTERN may contain variables, which will be interpolated (and the pattern recompiled) every time the pattern search is evaluated, except for when the delimiter is a single quote. (Note that $(, $), and $| are not interpolated because they look like end-of-string tests.) If you want such a pattern to be compiled only once, add a "/o" after the trailing delimiter. This avoids expensive run-time recompilations, and is useful when the value you are interpolating won't change over the life of the script. However, mentioning "/o" constitutes a promise that you won't change the variables in the pattern. If you change them, Perl won't even notice

    Notice that the text is only talking about patterns with variables in them (which is what the phrase "such a pattern" in what you quoted is referring to).

Re: Regex: same code works and fails, why?
by Abigail-II (Bishop) on Jan 07, 2004 at 16:30 UTC
    So, which variable is present in /^#/ ?

    Abigail

      Ah, so it only helps when there is variable in pattern. Makes sense. I must put this into account of failure to understand it correctly (as being non-native english speaker) and perhaps read the damn things more thoroughly :).