File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -830,20 +830,20 @@ of type L<Cool> are coerced to C<Str> for literal matching.
830
830
831
831
The replacement can be a L < Callable > in which the current L < Match > object will be
832
832
placed in the C < $/ > variable, as well as the C < $_ > topic variable.
833
- No thunking of arguments is done, so you need to use a L < Callable > replacement, to
834
- refer to any of the captures made in the regex:
833
+ Using a L < Callable > as replacement is how you can refer to any of the captures
834
+ created in the regex:
835
835
836
836
# Using capture from $/ variable (the $0 is the first positional capture)
837
837
say 'abc123defg'.subst(/(\d+)/, { " before $0 after " });
838
838
# OUTPUT: «abc before 123 after defg»
839
-
839
+
840
840
# Using capture from $/ variable (the $<foo> is a named capture)
841
- say 'abc123defg'.subst(/$<foo=\d+/, { " before $<foo> after " });
841
+ say 'abc123defg'.subst(/$<foo> =\d+/, { " before $<foo> after " });
842
842
# OUTPUT: «abc before 123 after defg»
843
-
843
+
844
844
# Using WhateverCode to operate on the Match given in $_:
845
- say " abc123defg" .subst(/(\d+)/, *.flip);
846
- # OUTPUT: «abc321defg »
845
+ say ' abc123defg' .subst(/(\d+)/, "[ " ~ *.flip ~ " ]" );
846
+ # OUTPUT: «abc[ 321 ]defg »
847
847
848
848
# Using a Callable to generate substitution without involving current Match:
849
849
my $i = 41;
You can’t perform that action at this time.
0 commit comments