phathead22 has asked for the wisdom of the Perl Monks concerning the following question:

How do you pass a diretory thru PERL in the DOS format (C:\perl\site...)
I've tried both back slashes and forward, with differing results, none of them as expected.
PH

Replies are listed 'Best First'.
Re: DOS directory naming in PERL?
by Caillte (Friar) on Jan 19, 2001 at 23:48 UTC

    Perl for dos (activestate at least) will work with both forward and backward slashes and drive specifiers. In other words, d:/index.html is ok, so is d:\\index.html. I suggest you chec your surrounding code

Re: DOS directory naming in PERL?
by mr.nick (Chaplain) on Jan 19, 2001 at 22:25 UTC
    Did you double escape them?
    open OUT,">C:\\windows\\foobar.txt"; print OUT "Ha!\r\n"; close OUT;
      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.

        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?