On 10.03.2009, at 21:25, John Delacour wrote:

At 21:10 -0600 9/3/09, Doug McNutt wrote:

At 22:24 -0400 3/9/09, Chris Devers wrote:
How can a Perl script reliably, portably resolve the path inside which
it is running?...

$0 That's a zero. Has always worked for me to produce a full path to a running perl script.

...There is a module "cwd"...

or rather Cwd. $0 will give the name but not the full path, so I'd suggest
the following:

#usr/bin/perl
use Cwd;
my $currentdir = cwd();
print "$currentdir/$0\n";

That's for a relative path. It would fail if $0 is an absolute path to begin with, the cases would have to be distinguished. To be truly portable, it should also make no assumptions about the directory separator. That's what Dir::Self (available on
CPAN) does.

Anno

Reply via email to