in reply to Re: Re: •Re: RegEx re-compilation
in thread RegEx re-compilation
Also note that some modern innovations make /o somewhat less nasty. The regex engine maintains a one-level cache, so if the regex to be compiled hasn't changed and was the most recent one compiled, the cached compilation is reused. That means you don't need /o for this:
In older Perls, that regex would have been recompiled for each element of @list. Not so, now. Even works for stuff like this:my @winners = grep /prefix$part/, @list;
as long as the rest of the loop doesn't use any other recompile-on-demand regex. But the moment it does, you've got two regexes both being compiled on each iteration, and you get molasses at that point.while (<>) { next unless /prefix$part/; ... }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: Re: Re: •Re: RegEx re-compilation
by Melly (Chaplain) on Nov 17, 2003 at 15:06 UTC |