in reply to Why does a Perl 5.6 regex run a lot slower on Perl 5.8?
The conclusion is that all regular expressions written like this: $text =~ /(.*?)<whatever>/ take a thousand times more on 5.8.0. The same expressions written as $text =~ /^(.*?)<whatever>/ which obviously means the same thing (look for the first occurence of <whatever> and save the text preceding it in the corresponding variables) has the same performance implications across these two versions.Sadly, that is not true, and that is exactly what I had to change in the source of perl. You say that /(.*)X/ and /^(.*)X/, but that is a half-truth. Consider this case: "xxyyyRyyy" =~ /(.*)R\1/ If, as you state, the leading ^ is implied, the regex fails, because "xxyyy" cannot be found after the "R" as my regex requires. Only by not anchoring that regex can it ever match ($1 is "yyy").
There is no "easy" way to fix this problem in the source of perl; you have to explicitly state the anchor yourself. The reason is that perl has no way of knowing whether or not you'll end up using what you captured as a backreference, so anchoring has an unknown effect. The problem is not only when the .* is captured, either; any capturing in the regex causes a problem.
(The case of "abc\ndef1" =~ /.*\d/ is already handled by the engine so as not to fail. It would fail if the regex were treated as /^.*\d/, but the engine makes it (?m:^) if necessary.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The Deceiver
by perldeveloper (Scribe) on Aug 13, 2004 at 14:04 UTC | |
by itub (Priest) on Aug 13, 2004 at 14:41 UTC | |
by perldeveloper (Scribe) on Aug 13, 2004 at 14:55 UTC | |
by tilly (Archbishop) on Aug 14, 2004 at 01:15 UTC | |
by itub (Priest) on Aug 13, 2004 at 15:12 UTC | |
by itub (Priest) on Aug 13, 2004 at 15:27 UTC | |
by japhy (Canon) on Aug 13, 2004 at 14:08 UTC | |
by Jenda (Abbot) on Aug 17, 2004 at 22:05 UTC |