Skip to content

Instantly share code, notes, and snippets.

@bazzaar
Last active May 16, 2020 16:51
Show Gist options
  • Save bazzaar/7a81009e383e6aff11594f1626c668f2 to your computer and use it in GitHub Desktop.
Save bazzaar/7a81009e383e6aff11594f1626c668f2 to your computer and use it in GitHub Desktop.
Are prior regex captures supposed to be scrubbed once subst method is called?
> my $s = 'aaa123bbb'
aaa123bbb
> $s ~~ m/ ('a' **3) \d**3 ('b' **3)/
「aaa123bbb」
0 => 「aaa」
1 => 「bbb」
> my $regex = / ('a' **2) 'a' \d**3 'b' ('b' **2) /
/ ('a' **2) 'a' \d**3 'b' ('b' **2) /
> $s .= subst($regex, $0 ~ "x999y" ~ $1)
aaax999ybbb
I would have expected the result to honour the captures in $regex being evaluated in the subst method call, producing:
aax999ybb
Answer: (By MasterDuke)
$s .= subst($regex, {$0 ~ "x999y" ~ $1}) # need to put the replacement into a block (#callable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment