in reply to Re: replacing backward slash with forward slash
in thread replacing backward slash with forward slash

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: replacing backward slash with forward slash

Replies are listed 'Best First'.
Re^3: replacing backward slash with forward slash
by dasgar (Priest) on Aug 19, 2011 at 14:49 UTC

    The double quotes interpolate and the single quotes don't. What that means is that in your code, perl is treating the backslashes as an escape character. To avoid that you either need to escape the backslash in double quotes or just use single quotes. The two variables below will have the same string.

    $str1 = "C:\\first\\second"; $str2 = 'C:\first\second';
    On another system, a string is declared in double quotes and is printing fine.

    Are you sure that you have the exact some perl code on both systems? Personally I can't think of any reason why perl would behave differently with regards to double quoting a string across different versions of perl or across different platforms. If I'm wrong about that, guess I'll have something new to learn.

Re^3: replacing backward slash with forward slash
by Anonymous Monk on Aug 19, 2011 at 09:26 UTC

    I am getting desired output. So why is single quotes working and double quotes is not working ?

    Both are working.

    Single quotes work different from double quotes

    If you want to know why, read the manual