I started today getting a problem with visual studio code and powershell running perl scripts.
After some debugging I found that I can not get the full path of the libraries anymore. For some reason powershell in visual studio code is returning the paths without the disk letter.
I made this script files to test it:
test.pm
package Utils::test;
use strict;
use File::Basename;
use Exporter 'import';
our @EXPORT_OK = qw(test);
sub test{
print(__FILE__."\n");
}
1;
test.pl
use strict;
use File::Basename;
use Utils::test;
Utils::test->test()
In PowerShell:
In windows cmd:
In visual studio code power shell:
Both PS instances return the same versions:
Version
-------
5.1.19041.1320
I'm not sure if there was an update in Visual Studio Code since this started happening but it is right now in 1.65.0
.
I have no idea if this is an issue with powershell, perl or visual studio code.
Update: From the comments, it seems that there is a linux shell in my windows PS:
Update2: Thanks again to @ikegami it seems there are two different perls installed:
CodePudding user response:
__FILE__
has always been the path used to open the file.
$ cat a.pl
CORE::say __FILE__;
$ perl a.pl
a.pl
$ perl ./a.pl
./a.pl
$ perl ././././a.pl
././././a.pl
$ perl ~/tmp/a/a.pl
/home/ikegami/tmp/a/a.pl
(Linux used here, but it's the same on Windows.)
If you want an absolute path, you can use
use Cwd qw( abs_path );
abs_path( __FILE__ )
CodePudding user response:
Thanks to the hints of @ikegami I have been able to track back what the issue was. There was another version of perl running in a MSYS which seems to be from git as $Env:Path
showed.