Welcome to the Monastery | |
PerlMonks |
RE: Answer: Regex anchor speed ?: Is /^.*X/ faster than /X/ ?by Dominus (Parson) |
on Nov 12, 2000 at 22:25 UTC ( [id://41205]=note: print w/replies, xml ) | Need Help?? |
Ovid said:
> The /^.*\@/ is forced to match toBut that is not exactly true. In general, Perl does behave that way. But in some cases, such as this one, there is an optimization: Perl sees that the string can't match unless it contains a @ character, so it looks for the @ first, and works outwards from there. In particular, it does not let .* match all the way to the end of the string and then backtrack it; it gets the right length for .* on the first try. Isn't that interesting? The nongreedy .*? version is optimized similarly, so I would be surprised if it performed any differently in this example.
In Section
Seekers of Perl Wisdom
|
|