On Thu, Aug 16, 2012 at 10:55 AM, Gergely Buday <gbu...@gmail.com> wrote:

> 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 <irfan_sayed2...@yahoo.com> 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: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
That or replace the " with ' and all wil be fine.

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

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

Regards,

Rob

Reply via email to