in reply to Why can't $` $& $' be enabled on a per-regex basis?
Because we're jerks. Patches welcome.
Seriously, it's a hard problem. Consider:
my @options = qw( foo bar ); my $string = $options[ rand @options ]; $string =~ /(foo)/; $string =~ /(bar)/; print $1;
Since there's no way of telling which option $string will contain, there's no way of telling which regex will match successfully until one actually does match successfully. (See perlvar, and note the phrase "last successful match".) The regex engine therefore has to keep track of all of the data to populate the magic variables in every regular expression.
japhy had some ideas to make this block scoped, and they may find their way into 5.10, but the problem remains hard.
|
|---|