How to directly get the script-path.

Z

ZZT

Hi,

I'd like to get the directory of the currently running script (not the
working directory) but without concat constructs with $0 and getcwd().
Is there an easy way, an internal or ENV var?

thanks a lot
 
S

Sam Holden

Hi,

I'd like to get the directory of the currently running script (not the
working directory) but without concat constructs with $0 and getcwd().
Is there an easy way, an internal or ENV var?

perldoc -q "directory my program lives in"
 
P

Paul Lalli

Hi,

I'd like to get the directory of the currently running script (not the
working directory) but without concat constructs with $0 and getcwd().
Is there an easy way, an internal or ENV var?

thanks a lot


You might want a combination of File::Basename::dirname and
File::Spec::rel2abs. Something like this, perhaps:

[untested]
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Spec;

my $dir = File::Spec->rel2abs(dirname($0));

print "$dir\n";


Paul Lalli
 
J

John J. Trammell

I'd like to get the directory of the currently running script (not the
working directory) but without concat constructs with $0 and getcwd().
Is there an easy way, an internal or ENV var?

perldoc FindBin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top