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

I would like to know how to find out the path of the current file, be it a script or a library. I know the info is there somewhere, because caller() returns the file a subroutine was called from. Is there a way to access this directly?

                - Ant
                - Some of my best work - (1 2 3)

  • Comment on Finding the path of the current library/file

Replies are listed 'Best First'.
Re: Finding the path of the current library/file
by ysth (Canon) on Aug 04, 2004 at 18:41 UTC
      OOOH yeah.. I have seen that before! Duh. Thanks.

                      - Ant
                      - Some of my best work - (1 2 3)

Re: Finding the path of the current library/file
by Eimi Metamorphoumai (Deacon) on Aug 04, 2004 at 18:48 UTC
    use File::Spec; print File::Spec->rel2abs(__FILE__);
Re: Finding the path of the current library/file
by EdwardG (Vicar) on Aug 04, 2004 at 18:50 UTC

    __FILE__ gives you the current filename, eg "cwd.pl".

    To get the current working directory use Cwd

    use Cwd; $dir = getcwd;