in reply to Regex Substitution, Interpolating on the RHS?
So you make the closure return a ref to the string you want, and deref it in the replacement. It will be evaluated at replacement time, and you get the substitution you're looking for.
my $regex = ['(foo)',sub {\"bar$1"}]; my $string = 'blah foo blah'; $string =~ s/$regex->[0]/${$regex->[1]->()}/; print "S=$string\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Substitution, Interpolating on the RHS?
by Cody Pendant (Prior) on Jul 18, 2005 at 23:30 UTC | |
by Roy Johnson (Monsignor) on Jul 19, 2005 at 13:20 UTC |