Here is the correct version:

#!/usr/bin/perl

$csproj_text = "C:\\build.txt";

$csproj_text =~ s/\\/\\\\/g;
print "$csproj_text\n";

Notice that in order to put a literal backslash into a perl string,
you should escape it. In your original program, you have put a \b, a
bell character into the string.

- Gergely

On 16 August 2012 10:48, Irfan Sayed <[email protected]> wrote:
> hi,
>
> i have following code to search single "\" and replace it with "\\"
> but it is not doing as expected:
>
> $csproj_text = "C:\build.txt";
>
> $csproj_text =~ s/\\/\\\\/g;
> print "$csproj_text\n";
>
> the output is : "Cuild.txt"
> instead the output should be : "C:\\build.txt"
> can someone please suggest, what is the wrong ?
>
> regards
> irfan

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to