How do I get the full path to a Perl script that is executing?
1. Using $0 and Cwd’s abs_path()
$0 contains the script name, which may be relative or absolute, depending on how the script was invoked. By using the Cwd module’s abs_path() function, you can ensure you get the absolute path.
use Cwd 'abs_path';
print abs_path($0);
This approach works well most of the time, except in some environments like mod_perl, where $0 may behave unexpectedly.
Labels: How do I get the full path to a Perl script that is executing?
