in reply to escaping the backslash
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:
In your case you need two literal backslashes so you have to enter four in the replacement.print "A backslash \\ is here\n";
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:
or betters/\\/\\\\/g;
(The second version is a bit more readable.)s{\\}{\\\\}g ;
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: escaping the backslash
by joedoc (Initiate) on Apr 29, 2003 at 21:36 UTC | |
by reds (Novice) on Apr 29, 2003 at 21:46 UTC | |
by joedoc (Initiate) on Apr 30, 2003 at 19:07 UTC |