Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top