in reply to How to obtain current working directory
use Cwd; my $dir = getcwd; print "$dir\n";
Cwd.pm is the preferable method. However, if you really need to use $0 instead of Cwd, you could use File::Basename like this:
use File::Basename; my $dir = dirname( $0 ); print "$dir\n";
Update: As davis has reminded us, the current working directory is not necessarily the same thing as the directory where the script is located. If you want the former, use the Cwd approach. If you want the latter, use the dirname( $0 ) approach.
Dave
|
|---|