in reply to perl6 match variable

The argument-less lambda block

{ ... }

is shorthand for

-> $_ { ... }

and $/ gets passed as argument to that.

You could use

-> $match { ... }

instead to access $/ as $match

The match object $/ in not visible on its own because subst evaluates the regex in a different scope.

Replies are listed 'Best First'.
Re^2: perl6 match variable
by jeckyhl (Novice) on Sep 09, 2014 at 21:30 UTC

    luminous! thank you

Re^2: perl6 match variable
by grondilu (Friar) on Sep 10, 2014 at 09:56 UTC
    The match object $/ in not visible on its own because subst evaluates the regex in a different scope.

    Does it? Because when I write, e.g:

    say "foo".subst: /(fo)o/, {$/[0].flip}

    I get, as I expected, "of"

      And now let's try

      for dir(".") -> $file { say "foo".subst: /(fo)o/, {$/[0].flip}; last; }

      guess what happens ?...

      we get an empty string!