in reply to s/$foo/$bar/ when $foo has metacharacters in it
You can use quotemeta, either as a function, or as \Q...\E (update: Relashed my slashes, thanks ikegami):
$b = quotemeta $b; $a =~ s/$b/$c/g; #or $a =~ s/\Q$b/$c/g; # \E not needed at end of pattern
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: s/$foo/$bar/ when $foo has metacharacters in it
by bcrowell2 (Friar) on Dec 20, 2007 at 22:46 UTC |