Perl's quotemeta
operator typically works on the SEARCH side of s///
, but in generating code to be compiled with eval
, how should I protect the REPLACEMENT that should be used literally but may contain bits such as $1
?
With code of the form
my $replace = quotemeta $literal_replacement;
my $code = eval <<EOCode;
sub { s/.../$replace/ }
EOCode
when will it produce syntax errors or surprising results?