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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.