Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re^3: Find the full path of the script at run time

by ibanix (Hermit)
on Mar 13, 2003 at 00:29 UTC ( #242553=note: print w/replies, xml ) Need Help??


in reply to Re^3: Find the full path of the script at run time
in thread Find the full path of the script at run time

Welp, I tried
use File::Spec::Functions qw(rel2abs); print "I am ", rel2abs($0), "\n";
and it works. It returns the exact same thing, in this one specific case, as plain $0.

First, thanks for all the help! :-)

Second, the decision. I have a bunch of scripts to convert. They will all be shared on a network drive and our team will run them over the network. I need the path so I can determine where the config files for the scripts are, on the fly, even if the whole set of scripts move to another location. This setup will let us always stay in-sync and share scripts, etc.

Is it going to be worthwhile for me to put in the full-blown  use File::Spec::Functions qw(rel2abs);, or can I get away with just $0? This is a judgement call, but I want your judgements! :-)

Update:

After some experimentation, I've decided to go with the following for finding the directory my scripts are running in.
use File::Spec::Functions qw(rel2abs splitpath catpath); (my $vol, my $dirs, undef) = splitpath( rel2abs($0) ); my $path = catpath( $vol, $dirs, undef ); print "I am ", $path, "\n";
Thanks!
ibanix

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://242553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-08-08 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?