|There's more than one way to do things|
Re: Regexp optimization - /o option better than precompiled regexp?by ikegami (Pope)
|on Jun 27, 2010 at 20:32 UTC||Need Help??|
Patterns without interpolation are compiled when their quoting operator (m//, s///, qr//) is compiled. /o shouldn't matter one bit for those, so I won't discuss them.
Patterns with interpolation are compiled when their quoting operator (m//, s///, qr//) is executed.
Perl caches compiled regex patterns to avoid needless recompilation in situations like the following:
A match or substitution operator can only resuse the last regex is compiled, so the following isn't efficient:
You can use qr// to precompile a pattern.
Note that Perl currently flattens and recompiles compiled patterns interpolated into another pattern.
This should be optimised in the future.