Since the issue is the interpolation of the replacement string, can you not stamp on '$' and '@', leaving only '$1' et al ? That is:
Noting that you don't want to "activate" '\$' or '\@' by inserting '\'.use strict ; use warnings ; while (<DATA>) { my ($pat, $repl) = (split '/') [1, 2]; # Escape $ and @ preceded by an even number of '\', except for $1 +etc. $repl =~ s/(?<!\\)((?:\\\\)*(?:\$(?!\d)|\@))/\\$1/g ; my $e = "\$s =~ s/$pat/$repl/" ; my $s = "foo"; print "$e '$s' -> " ; eval $e ; die $@ if $@ ; print "'$s'\n" ; } __DATA__ s/foo/bar/ s/(fo)o/bar$1/ s/oo/\${system "echo hello sailor !"}/ s/oo/\\${system "echo hello sailor !"}/ s/oo/\\\${system "echo hello sailor !"}/ s/oo/\\\\${system "echo hello sailor !"}/ s/oo/\\\\\${system "echo hello sailor !"}/ s/oo/@{system "echo hello sailor !"}/ s/oo/\@{system "echo hello sailor !"}/ s/oo/\\@{system "echo hello sailor !"}/
Hope I didn't miss anything...
In reply to Re^3: Slurping search-replace patterns from a file
by gone2015
in thread RESOLVED: Slurping search-replace patterns from a file
by HKS
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |