Oh, :-), well then Ill add another point. Mostly everybody knows that $` and $& and $' incur a global performance penalty. What they probably dont know is why, and the reason is the part where I mentioned that the magic regex vars work against a copy of the original string (not always actually, but pretty close). In the case of capture buffers the regex engine knows it needs to copy the string because it knows the pattern has capture buffers in it. However for the evil regex vars there is no such cue in the pattern and when combined with the dynamic scoping of these vars Perl has to make a serious pessimisation to ensure that they always work: once it sees any of them it has to copy the original string for every match.

This is why in perl 5.10 we have the /p modifier. It tells Perl that we want to use $` $& and $' on the results of the pattern match. Except that we cant change the behaviour of $& and friends so it actually tells Perl that we want to use their non-evil counterparts ${^PREMATCH}, ${^MATCH} or ${^POSTMATCH} on the result of the match. Since the /p tells perl "copy the string when you do the match" there doesnt need to be a global effect, ${^MATCH} and friends only work when the pattern is executed with the /p modifier, and the programmer knows this. So perl doesnt have to be "clever" and pessimise to ensure that they will always work once its seen them.

---
$world=~s/war/peace/g


In reply to Re^4: @- and @+ question by demerphq
in thread @- and @+ question by Cristoforo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.