Ruud H.G. van Tol skribis 2005-09-26 21:27 (+0200):
> 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.

In Perl 6, the match object $/ will instead be used. It's a bit harder
to use with s///, because it will look ugly, but remember that you can
always choose to use s^^^ or s[][] or any other of the many
possibilities instead.

>   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.

> and there needs to be no $1 variable set up.

Perl 6 will count from 0, so it'll be $0.

> (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

K vnd grtz n btj mljk t lzn, n d z mt ntrljk n s zjn.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to