Reputation: 25117
What do I have to change here to make it work?
my $str = "start middle end";
my $regex = / start ( .+ ) end /;
$str.=subst( / <$regex> /, { $0 } ); # dies: Use of Nil in string context
say "[$str]";
Upvotes: 9
Views: 274
Reputation: 4329
The problem is that interpolating a regex into another regex via the <$regex>
syntax will not install a result in the match variable. There's two ways to get around this:
$str .= subst($regex, { $0 });
$str .= subst( / <foo=$regex> /, { $<foo>[0] });
Both of these should work fine.
Upvotes: 10