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

Hi, is there a way to find the full path of the .pm file implementing a module? One can manually search in @INC, but a bit tedious. How about if the package is in the current file? can one do this with a one-liner with "perl -e ..."? Thanks.

updated I'm not sure the question "How about if the package is in the current file?" makes sense. I'm refering to switching packages in the same file.

  • Comment on Finding the full path of a module implementation file

Replies are listed 'Best First'.
Re: Finding the full path of a module implementation file
by chromatic (Archbishop) on Aug 24, 2004 at 21:49 UTC

    I'm not sure I understand your update, but I normally use perldoc -l Module::Name. It works in 90% of my cases.

Re: Finding the full path of a module implementation file
by ikegami (Patriarch) on Aug 24, 2004 at 21:22 UTC
    >perl -MDBI -le "print($INC{'DBI.pm'});" r:/Utils/perl/site/lib/DBI.pm

    That's how you find the path to a module that's already been used. I'm not sure if it answers your question, however, especially since you're talking about packages. Packages are not associated with any file. Mutiple files can use the same package statement, and it's possible to add vars and subs to a package without using the package statement.

Re: Finding the full path of a module implementation file
by Aristotle (Chancellor) on Aug 24, 2004 at 21:58 UTC

    That's not a trivial problem in the general case. A package can be strewn across multiple files, and a file can contain (parts of) multiple packages.

    The common case were files and packages correspond to each other 1:1 is easy enough to solve and would usually be done using perldoc -l Module.

    If you need to cover more complex scenarios, though, you're on your own.

    Makeshifts last the longest.

Re: Finding the full path of a module implementation file
by eyepopslikeamosquito (Archbishop) on Aug 25, 2004 at 04:39 UTC

    I don't understand what you're trying to do exactly, but perl's __FILE__ variable may prove handy. Here is an example use of it from Net/Config.pm:

    my $file = __FILE__; my $ref; $file =~ s/Config.pm/libnet.cfg/;
Re: Finding the full path of a module implementation file
by johnnywang (Priest) on Aug 25, 2004 at 08:12 UTC
    Thank you all. I was looking for the "perldoc -l" or the %INC, both of which I wasn't aware of. Thanks.