How do I get the full path to a Perl script that is executing

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have Perl script and need to determine the full path and filename of the script during execution. I discovered that depending on how you call the script $0 varies and sometimes contains the fullpath+filename and sometimes just filename. Because the working directory can vary as well I can t think of a way to reliably get the fullpath+filename of the script.

Anyone got a solution?

Answers

$0 is typically the name of your program, so how about this?

use Cwd  abs_path ;
print abs_path($0);

Seems to me that this should work as abs_path knows if you are using a relative or absolute path.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/84932/how-do-i-get-the-full-path-to-a-perl-script-that-is-executing

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils