> Ruud H.G. van Tol:

>> Think about adding \& to the replacement part of a s///.
>> As in sed, the & means the whole match.
> Do you know Perl 5's $& variable? What you want isn't exactly new for
> Perl.

Yes I certainly know it. That it slows things down too.

A point was to not set up a variable. The \& is only a message for the
regex. An extra meaning for \1 could be to block the set up of a $1,
which might seem drastic but can help optimization.

>>   s/($search)/*\1*/go
> \1 in Perl 5 is bad style and emits a warning, if you were clever
> enough to enable warnings. \1 in Perl 6 strings will no longer have
> anything to do with regex matches.

It could be reinstated as "living in regex-engine-space only".

>> (I assume that using () always makes a $1 available, even if it is
>> not being used.)
> Perl 5's $& is inefficient because of this. If the variable is used
> anywhere, Perl will for every regex used capture everything. An
> implicit match string is far less efficient than an explicit one, in
> terms of Perl 5. Perl 6, however, will handle things smarter and not
> copy the substring until it needs to be. That's why the equivalent of
> $& will be usable without any frowning.


Grtz, Ruud

Reply via email to