perlpathgetcwdcwd

cwd and gwtcwd returns a linux style path on windows


If I run this script:

use Cwd;
print "$^O\n";
print cwd;

The output is:

C:\tmp>perl tmp.pl
msys
/c/tmp

How can I get windows style path C:\tmp?


Solution

  • It's because you're using built-in perl of msys, and this version of perl will definitely give a Linux-style path. If you installed Active Perl and use Active Perl to launch your script, the path would be Win32-style:

    $ /bin/perl5_8.exe path.pl
    msys
    /c/tmp
    
    $ /c/ActivePerl/bin/perl.exe path.pl
    MSWin32
    c:/tmp
    

    You could use alias in your bash profile to redirect perl to ActivePerl:

    alias perl /c/ActivePerl/bin/perl.exe
    

    Then:

    $ which perl
    perl is /c/ActivePerl/bin/perl