in reply to Re: $& as a read-only value
in thread $& as a read-only value

While I agree in general, I'd not call it grind its performance to a halt.

If I remember correctly from previous explanations the impact of using one of those variables makes perl copy every string that you match a regex against.

How much that is strongly depend on your application, and might range from "not measurable" to "makes your application crash" (when it runs out of memory).

I find these variables very useful when debugging complicated regex. I put something like this into the regexes at various places: (?{ print "&`«$&»$'\n" }) which shows pretty nicely how far the regex engine proceeded so far. (But you won't find that in production code ;-)

Replies are listed 'Best First'.
Re^3: $& as a read-only value
by Erez (Priest) on May 22, 2008 at 18:49 UTC

    I'd not call it grind its performance to a halt.

    The terminology might not be exact in terms of actual performance, but I found that phrase to leave an adequate impression every time the match variable and its kin appear in someone's code.

    You might say its fear mongering (and you might be right), but I'd rather exaggerate now, and debate facts after the usage of the match variables has been abolished (another strong word).

    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.