MrNobo1024 has asked for the wisdom of the Perl Monks concerning the following question:
I don't see why they had to make it set them on *every* regex match just because one uses them. Why couldn't they just add a new modifier (like /i, /x, /g, etc), and only set them if the modifier is used?WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in + the program, it has to provide them for every pattern match. This ma +y substantially slow your program. Perl uses the same mechanism to pr +oduce $1, $2, etc, so you also pay a price for each pattern that cont +ains capturing parentheses. (To avoid this cost while retaining the g +rouping behaviour, use the extended regular expression (?: ... ) inst +ead.) But if you never use $&, $` or $', then patterns without captur +ing parentheses will not be penalized. So avoid $&, $', and $` if you + can, but if you can't (and some algorithms really appreciate them), +once you've used them once, use them at will, because you've already +paid the price.
--MrNobo1024
s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why can't $` $& $' be enabled on a per-regex basis?
by chromatic (Archbishop) on Aug 10, 2002 at 07:05 UTC | |
|
Re: Why can't $` $& $' be enabled on a per-regex basis?
by Juerd (Abbot) on Aug 10, 2002 at 09:57 UTC | |
by tye (Sage) on Aug 10, 2002 at 16:39 UTC | |
|
Re: Why can't $` $& $' be enabled on a per-regex basis?
by Zaxo (Archbishop) on Aug 10, 2002 at 06:35 UTC | |
by Courage (Parson) on Aug 10, 2002 at 06:45 UTC |