Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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;

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found