chromatic is right, you should use the quote() or even better the placeholders. This is just to explain why what you tried didn't work.
The replacement string in a s/// is basicaly just a doublequoted string. In such a string if you want to include a literal backslash you have to escape it: print "A backslash \\ is here\n";
In your case you need two literal backslashes so you have to enter four in the replacement.
Second, the list of characters that need to be escaped in a regular expression is even longer than in a doublequoted string. What they both have in common is that you have to type two backslashes if you want to get a single literal backslash. So the line should look like this:
s/\\/\\\\/g;
or better s{\\}{\\\\}g ;
(The second version is a bit more readable.)
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature |