Question

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?

Was it helpful?

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

OTHER TIPS

You're not really on Windows, or $^O would be MSWin32. You're inside the MSYS unix emulation environment, so it's no surprise you have unix-style paths. For a version of Perl that runs on Windows natively, use ActivePerl or Strawberry Perl.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top