in reply to Re: Pass Matched Variable into Regex Replace Variable
in thread Pass Matched Variable into Regex Replace Variable

I feel like I've tried that and it didn't work.

perl -e '$t="begin{foobar}";$p="begin{(.*?)}";$r="\"end{\$1}\""; $t=~s/$p/$r/gee; print "$t\n\n"'
#Output: end{foobar}

Perhaps I'm doing something wrong? Edit:I didn't escape the dollar sign in the variable. The suggestion works. I'll apply it to my program and see if everything works :) Thank you!

Replies are listed 'Best First'.
Re^3: Pass Matched Variable into Regex Replace Variable
by Anonyrnous Monk (Hermit) on Dec 17, 2010 at 18:34 UTC
    $r="\"end{$1}\"";

    The double quotes interpolate the $1. Use $r=q("end{$1}") in this case.

      I actually did that in my production code, but it's worth mentioning for reference. :) cheers