I’m looking for a way to get two pieces of information:
- The full path of where a script resides including its filename
- The full path of where a script was executed from
I know you can use $0 to get the file name, but are there any other reserved variables that are native to Perl that will give me what I’m looking for?
I’d rather not use any special modules, but if it is the only way, then so be it.
the
PWDenvironment variable holds the current working directory, which should be the path the script was executed from.You can derive the full path of the script with
$ENV{PWD}and$0Edit: providing sample code since it is hard for some to believe this is possible:
I may not have caught all the possible cases, but this should get very close:
Output from test runs: