Perl metaprogramming: when is it unsafe to use quotemeta on the REPLACEMENT value of s///?

后端 未结 3 451
小蘑菇
小蘑菇 2021-01-14 16:25

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 tha

3条回答
  •  [愿得一人]
    2021-01-14 16:56

    The replacement is usually processed like a double-quoted string, but you can change that by using single-quotes as the delimiter:

    $test =~ s'$replace';
    

提交回复
热议问题