shahriar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to know the full path to the running script ( $0 provides the name of the file) is there a way to get the full path. for example: I run the script "/root/eng/perlscripts/xyz.pl" $0 = xyz.pl I need a way to know "/root/eng/perlscripts/xyz.pl" I asked around and was yold that "FindBin" provides this sort of functionality. However, after reading the manual pages for it. It seems that it might not be the right way to go because of this comment in the manual: "If there are two modules using FindBin from different directories under the same interpreter, this won't work. Since FindBin uses a BEGIN block, it'll be executed only once, and only the first caller will get it right. This is a problem under mod_perl and other persistent Perl environments, where you shouldn't use this module. Which also means that you should avoid using FindBin in modules that you plan to put on CPAN. To make sure that FindBin will work is to call the again function:" Is there another way to do the same thing wich is more robust without these issues. Thanks, -shahriar

Replies are listed 'Best First'.
Re: Is FindBin the correct way to go (rel2abs)
by tye (Sage) on Jan 26, 2006 at 07:49 UTC

    FindBin has other problems, such as the entire design being built around a fundamental misunderstanding of the problem (and the implementation being perverse in other ways).

    Why not just use rel2abs() from File::Spec or something similar from Cwd (if you care about more fancy canonicalization of symbolic link trickery)?

    - tye        

Re: Is FindBin the correct way to go
by jbrugger (Parson) on Jan 26, 2006 at 07:05 UTC
    You can allways set it in your script self (as a variable, or in a config file), but why don't you just use lib, since i assume you need the path for loading your modules?
    use lib qw(/rootdir/en/scriptdir/);
    (and for mod_perl set it in your startup.pl)

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.