On Mon, Sep 26, 2005 at 10:19:29PM +0200, Juerd wrote:
: 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.
It's always bothered me a little to use $/ "the object" when you
want to refer explicitly to the string matched, especially if the
object knows it matched more than the string is officially matching.
I think we could go as far as to say that $<> is the name of the text
that would be returned by ~$/ and the number that would be returned
by +$/. If we did that, I think we could get away with making
/frontstuff < \w* > backstuff/
a shorthand for
/<pre frontstuff> $<>:=( \w* ) <post backstuff>/
The space after the < would be required, of course. It works because
in the <foo \d*> form, the default is to take the argument as rule,
and here we merely have a null "foo".
That gives us cool things like
s/back \s+ < \d+ > \s+ times/{ $<> + 1 }/
to increment the number of times the quick brown fox jumped over the
lazy dog's back.
Larry