in reply to DOS directory naming in PERL?

Did you double escape them?
open OUT,">C:\\windows\\foobar.txt"; print OUT "Ha!\r\n"; close OUT;

Replies are listed 'Best First'.
Re: Re: DOS directory naming in PERL?
by Albannach (Monsignor) on Jan 19, 2001 at 22:34 UTC
    Even simpler IMHO is to avoid double quoting anything that will not need interpolating. I also use this as a quick visual clue of where demons may hide ;-)

    BTW, I didn't see the need for the "\r" in the print as in DOS\WIN32 the "\n" is really both CR and LF characters.

    open OUT,'>C:\windows\foobar.txt'; print OUT "Ha!\n"; close OUT;

    --
    I'd like to be able to assign to an luser

      (grin). Sorry, I'm so used to writing Unix code that reads and writes to DOS-style files that I automatically did it.

      So you are saying that the Dos/Win32 version of PERL correct interprets \n as the CR/LF combo? Interesting.

        See perldoc perlop, and look for "Quote and Quote-like Operators". \n is "virtual" with respects to Perl in that does not map to a single ASCII byte irrespective of OS. It assumes the OS's representation of a "newline". Under Unix, this is equivalent to \cJ. Under DOS/Windows, it's \cM\cJ. Likewise, I think \r behaves differently under MacOS as well, for the same reasons.
      I would have to disagree. Single quotes work fine when you have a backslash followed by anything but a backslash, but if you try to use two backslashes together (as in '\\foo') they will escape into one backslash. Does anyone know how to avoid this? Strings like '\\\\192.168.1.1' to get \\192.168.1.1 are ugly.

      The best I could come up with is:

      print <<'' . " is the UNC name" \\192.168.1.1
      But this leaves an extra newline at the end of the IP address. Am I missing something blatently obvious?
        In any quoted string ("", '', qq{}, q{}, etc.), a double backslash must be interpolated as a single backslash, because a backslash is used to escape the quoting character(s). This makes it possible to get the one character string \ and the two character string \', with '\\\'' and '\\', respectively.

        Here-docs are the exception to this. One can always find a terminator, possibly several characters long, that doesn't appear within the string itself. Thus, backslashes are free to be regular characters in a here-doc.

        I don't think you're missing anything; this is just how strings work in Perl.