Skip to content

Commit

Permalink
Clarify difference between $¢ and $/, refs #1760
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 25, 2018
1 parent fc50ce3 commit 5a04e5d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion doc/Type/Match.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ B<Note>: This feature works only from Perl 6 version 2018.02. It would have
returned C<Nil> with any previous version. Alternatively and prior to that
version, you could use C<$/> which, inside the regex, has the same value:
m: '123' ~~ / (\d) { say $0; say $/; } \d+ /; # OUTPUT: «「1」␤「1」␤ 0 => 「1」␤»
'123' ~~ / (\d) { say $0; say $/; } \d+ /; # OUTPUT: «「1」␤「1」␤ 0 => 「1」␤»
The main difference between C<$/> and C<> is scope: the latter only has a
value inside the regex:
'123' ~~ / (\d) { say $/; say $¢; } \d+ /; # OUTPUT: «「1」␤ 0 => 「1」␤「1」␤ 0 => 「1」␤»
say "¢ → ", $¢, "/ is $/"; ; # OUTPUT: «¢ → Nil/ is 123␤»
Submatches are also C<Match> objects (or lists of C<Match> objects,
if the corresponding regex was quantified), so each match object
Expand Down

0 comments on commit 5a04e5d

Please sign in to comment.