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

I can't seem to figure this one out. How can I, from the command line, determine where on the filesystem a module would be loaded from? I.E., I want to say something like "if I 'use module;' where on the filesystem would perl get module.pm?"
  • Comment on find filesystem path of module from command line

Replies are listed 'Best First'.
Re: find filesystem path of module from command line
by davorg (Chancellor) on Nov 21, 2001 at 13:58 UTC

    I don't think that the other solutions posted take into account any changes to @INC that you might make using $PERL5LIB or use lib.

    I'd use the contents of the %INC hash. The keys of the hash are the module names and the values are the corresponding paths. For example:

    perl -MCGI -le "print $INC{'CGI.pm'}"
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

Re: find filesystem path of module from command line
by chipmunk (Parson) on Nov 21, 2001 at 06:59 UTC
    I generally use perldoc -l Module, which simply displays the path to the module (or script, or POD documentation). I also use it when I want to view a module's source in emacs, as in emacs `perldoc -l Module`.

    See perldoc for more on this handy utility.

      I generally use perldoc -l Module, which simply displays the path to the module (or script, or POD documentation).
      Except when the file's documentation has been ripped out to a .pod file, because you'll get the path to the POD, not the PM. Bleh. But the PM is almost always nearby. {grin}

      -- Randal L. Schwartz, Perl hacker

Re: find filesystem path of module from command line
by blakem (Monsignor) on Nov 21, 2001 at 06:16 UTC
    How about:
    % perl -le 'print for @INC' /usr/local/perllibs /usr/local/lib/perl5/5.6.1/i586-linux /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/i586-linux /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .
    At least that gives you a list to work from.... You can also examine the output of perldoc perllocal which will provide information about locally installed modules:
    % perldoc -t perllocal | grep -A 8 Digest::MD5 Tue Aug 28 15:29:48 2001: "Module" Digest::MD5 * "installed into: /usr/local/lib/perl5/site_perl/5.6.1" * "LINKTYPE: dynamic" * "VERSION: 2.16" * "EXE_FILES: "

    -Blake

      I'm aware of how Perl looks for modules and could figure it out based on such output, but am curious if there is a more direct way. Something like the (caller(0))1 function, but where I could supply an argument of module.pm. Any ideas? Thanks for your help.
      great! thanks!
Re: find filesystem path of module from command line
by Rich36 (Chaplain) on Nov 21, 2001 at 20:22 UTC
    You could also use this piece of code - findINC. It's a script I wrote to find modules and their location, so it does display the full path.
    Rich36
    There's more than one way to screw it up...