I am trying to implement a perl script and I need to get a directory of my executed file.
For example if my file that I'm executing is at
# The initial variable with file
say $0; # C:\Users\sed\AppData\Roaming\npm\node_modules\my-test-module\my-test-file
# This is just a current directory
say dirname($0); # .
# This looks like a bug to me, the shell is opened in C:/Users/sed so it is related
say abs_path($0); # /c/Users/sed/C:/Users/sed/AppData/Roaming/npm/node_modules/my-test-module\my-test-file
# This is what I need, except I don't need that first UNIX looking part
say dirname(abs_path($0)); # /c/Users/sed/C:/Users/sed/AppData/Roaming/npm/node_modules/my-test-module
A quick look at:
shows why it may not be the best choice for what you need to do. Please try File::Spec instead.
C:\Users\Ken> echo C:\Scripts\MyScript.pl | perl -MFile::Spec -lne "print $_; ($v,$d,$f)=File::Spec->splitpath($_); print $v.$d;" C:\Scripts\MyScript.pl C:\Scripts\
for more information. BTW, I tested with Strawberry perl v5.24.1