http://www.perlmonks.org?node_id=846782


in reply to Regexp optimization - /o option better than precompiled regexp?

it seems that option /o offers better performance that precompiled regexp.

A "precompiled regexp" is one that has no variables and is therefore compiled at compile-time, for example m/999986/ or m/^abc.*def/.    Any regexp that contains a variable has to be compiled at run-time.    The /o option means that the regexp is interpolated and compiled only once for the complete life of the program.    Any other regexp that requires variable interpolation has to be interpolated and compiled each time that regexp is used.    The qr// operator allows you to interpolate and compile a regexp once, at run-time, for example from user input.

Replies are listed 'Best First'.
Re^2: Regexp optimization - /o option better than precompiled regexp?
by Anonymous Monk on Jun 28, 2010 at 05:00 UTC

    "The /o option means that the regexp is interpolated and compiled only once for the complete life of the program."

    But why then is main::CORE:regcomp still being called on every iteration, just as in the cases without /o?