in reply to Re: Re: Glob on Win32: porting 5.005 to 5.6
in thread Glob on Win32: porting 5.005 to 5.6

Glad you got it sorted. Perl's automagical conversion of / to \ for Win 32 is great. If you want to get Win32 type names for display to users you just do something like this:

my $perl = '/foo/bar/baz'; (my $win = $perl) =~ tr!/!\\!; print "Perl still sees: $perl\n"; print "But we can print: $win\n";

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
/ vs. \ in Win32 (Re: Glob on Win32: porting 5.005 to 5.6)
by tye (Sage) on Sep 04, 2001 at 19:19 UTC
    Perl's automagical conversion of / to \ for Win 32 is great.

    Mostly FYI, Perl doesn't convert / to \ for Win32. Win32 itself accepts / as a path separator almost everywhere. Even command.exe accepts / as a path separator. But most tools from Microsoft that access file names on their command line don't allow / as a path separator (because they use / to introduce command-line options).

    Strangely, "open file" dialogues also don't accept / as a path separator, though I can find no reason why that should be (and this doesn't affect your Perl code unless you are stuffing fake keystrokes into a GUI with Perl, which is how I noticed this).

    Also, the Registry doesn't allow / as a key path separator because you can use / as part of a key name. Luckilly, Win32::TieRegistry deals with this rather well so Perl coders don't have to fret about it.

    So it is often best to use / as your directory path separator in Perl and convert / to \ if you need to hand the path to an external program on its command line.

            - tye (but my friends call me "Tye")

      Even command.exe accepts / as a path separator.

      If command.com accepts / then why does it fail in the last case?

      C:\>type test.bat REM Hello tye! C:\>type .\test.bat REM Hello tye! C:\>type ./test.bat Invalid switch - /TEST.BAT C:\>test.bat C:\>REM Hello tye! C:\>.\test.bat C:\>REM Hello tye! C:\>./test.bat Bad command or file name C:\>

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        That was the type of thing I had tested before but testing it now shows command.exe not supporting it. It appears that I am correct that command.exe supports / as a directory path separator, it just doesn't always support it:

        C:\>c:/temp/cleanpath.bat Cleaning user-specific PATH: ...

        Using Microsoft software, I often boggle.

                - tye (but my friends call me "Tye")
        Microsoft showing what they really think of Slashdot? :)
        I get another error, not 'Bad Command...' but instead:
        '.' is not recognized as an internal or external command, operable program or batch file.
        I suppose it's because I'm on Win2K, but it does seem to give a clue as to how Windows parses the command line...

        --- perchance