Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Module installed Path

by rose (Beadle)
on Mar 06, 2007 at 08:36 UTC ( #603362=perlquestion: print w/replies, xml ) Need Help??
rose has asked for the wisdom of the Perl Monks concerning the following question:

Hi Greate Monks,

We can use @INC or %INC to get the path of all the modules.

Is there any option to get individual module installed path? Say for example I need to know the installed path of File::Find module


Replies are listed 'Best First'.
Re: Module installed Path
by davorg (Chancellor) on Mar 06, 2007 at 09:54 UTC

      That's only if perldoc -l File::Find doesn't work, right? :)

Re: Module installed Path
by rodion (Chaplain) on Mar 06, 2007 at 10:47 UTC
    I've found the shell script by jhourcle at Re: Which module did I load? very helpful. It not only tells you which of multiple copies in your @INC path is the module perl is using, it gives you the version number and the other modules that will be loaded with it. Here's his sample invocation and partial output, copied from the node in the link.
    $ whichpm CGI : /System/Library/Perl/5.8.6/ CGI/ : /System/Library/Perl/5.8.6/CGI/ : /System/Library/Perl/5.8.6/ ...

      You may try which_pm as well. It comes with Module-Which distribution and also shows the module version number.

      $ which_pm CGI CGI 3.15 /usr/local/lib/perl5/5.8.8/ $ which_pm CGI:: --p5p CGI::Cookie 1.26 at ${installprivlib}/ CGI::Util 1.5 at ${installprivlib}/ CGI::Pretty 1.08 at ${installprivlib}/ CGI::Carp 1.29 at ${installprivlib}/ CGI::Push 1.04 at ${installprivlib}/ CGI::Switch 1.00 at ${installprivlib}/ CGI::Apache 1.00 at ${installprivlib}/ CGI::Fast 1.05 at ${installprivlib}/ CGI::Session 4.20_1 at ${installsitelib}/ CGI::Session::Driver 4.20 at ${installsitelib}/ [SNIP] from Config: installprivlib: /usr/local/lib/perl5/5.8.8 installsitelib: /usr/local/lib/perl5/site_perl/5.8.8
Re: Module installed Path
by vrk (Hermit) on Mar 06, 2007 at 08:44 UTC

    I don't know if there's an official way, but here's what I could whip together:

    sub find_installed_path { my $module_name = shift; # For Unix systems: $module_name =~ s!::!/!g; # For Windows: #$module_name =~ s!::!\\!g; $module_name .= '.pm'; foreach my $path (@INC) { next if (ref $path); return "$path/$module_name" if (-f "$path/$module_name"); } return ''; } print find_installed_path('File::Find');

    YMMV, but works with Linux and Perl 5.8.8.

    UPDATE: @INC may contain references (to subroutines, blessed objects, etc.), so added a check right at the beginning of the foreach loop.

    print "Just Another Perl Adept\n";

Re: Module installed Path
by leocharre (Priest) on Mar 06, 2007 at 16:25 UTC
    This is a sub I use as part of a man.cgi app, an interface to look up perl docs.
    use strict; use Pod::Simple::Search; use constant DEBUG => 0; for (qw( File::PathInfo HTML/ Smart::Comments)){ my $name = $_; my $returned = lookup_as_perl($name); print " ARG: $name = $returned\n"; } sub lookup_as_perl { my $arg_name = shift; print STDERR "lookup_as_perl() $arg_name, " if DEBUG; $arg_name=~s/^\/+//; # take out leading slashes $arg_name=~s/\/+/\:\:/g; $arg_name=~s/\.html$|\.pod$|\.pm$//; $arg_name=~s/\/+/\:\:/g; print STDERR "cleaned to $arg_name, " if DEBUG; #can we find this? my $search = Pod::Simple::Search->new; my $result = $search->find($arg_name); $result ||= 0; print STDERR "result = $result\n" if DEBUG; return $result; } # returns ... #[betti@mescaline cgihelp]# perl # ARG: = /usr/lib/perl5/5.8.8/ # ARG: File::PathInfo = /usr/lib/perl5/site_perl/5.8.8/File/PathInfo.p +m # ARG: CGI::Carp = /usr/lib/perl5/5.8.8/CGI/ # ARG: Smart::Comments = /usr/lib/perl5/site_perl/5.8.8/Smart/Comments # ARG: HTML/ = /usr/lib/perl5/site_perl/5.8.8/HTML/Template
Re: Module installed Path
by jesuashok (Curate) on Mar 06, 2007 at 09:45 UTC
    perldoc perllocal will list the names of locally installed modules.

    Refered from here

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603362]
Approved by graq
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2017-03-30 10:16 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (356 votes). Check out past polls.