Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

Thanks,
Rose

Comment on Module installed Path
Select or Download Code
Re: Module installed Path
by w-ber (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 jesuashok (Curate) on Mar 06, 2007 at 09:45 UTC
    perldoc perllocal will list the names of locally installed modules.

    Refered from here
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 CGI.pm : /System/Library/Perl/5.8.6/CGI.pm CGI/Util.pm : /System/Library/Perl/5.8.6/CGI/Util.pm Carp.pm : /System/Library/Perl/5.8.6/Carp.pm ...

      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/CGI.pm $ 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 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(CGI.pm File::PathInfo HTML/Template.pm 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 test.pl # ARG: CGI.pm = /usr/lib/perl5/5.8.8/CGI.pm # 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/Carp.pm # ARG: Smart::Comments = /usr/lib/perl5/site_perl/5.8.8/Smart/Comments +.pm # ARG: HTML/Template.pm = /usr/lib/perl5/site_perl/5.8.8/HTML/Template +.pm

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603362]
Approved by graq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-10-21 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (111 votes), past polls