in reply to perl6: subst with capture brackets

It's not yet implemented (and not very easy to do :/, I've tried it twice so far, with no luck.)

If you want to use the match object in the substitution part, there's an ugly workaround, which is to use the method form of subst, and using the first positional parameter:

my $v = "test"; $v.=subst(/(\w)/, -> $/ { say $0; 'X' }); say $v # output: t Xest

I know that $/ should be available in the substitution part, but I'm not sure what the spec says about the outside - especially in the case of s:g/// this wouldn't make all too much sense.

Update: both forms, as well as using $0 in the right-hand side of the s/// work now in rakudo.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: perl6: subst with capture brackets
by Fox (Pilgrim) on Aug 16, 2010 at 12:52 UTC
    Ah ok, thanks for the heads up and the workaround.