in reply to How to 'escape' a character in a string?
You need to convert the delimiter into a regex pattern that matches the delimiter. That's what quotemeta does.
my $pat = quotemeta($delim); s/$pat/\\$delim/g;
quotemeta can be accessed with \Q..\E in regex literals (among others).
s/\Q$delim\E/\\$delim/g;
or
s/\Q$delim/\\$delim/g; # \E is optional at the end of the literal.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to 'escape' a character in a string?
by VingInMedina (Acolyte) on May 23, 2012 at 17:38 UTC |