http://www.perlmonks.org?node_id=748665

manish.rathi has asked for the wisdom of the Perl Monks concerning the following question:

How to check what perl modules are installed on my computer ?

How to check contents of each module ?

Replies are listed 'Best First'.
Re: perl modules
by ELISHEVA (Prior) on Mar 05, 2009 at 22:06 UTC

    instmodsh only shows your locally installed modules - that is, the things you installed using CPAN. It will not list core modules or things that automatically come with your Perl distribution (for example, the debconf modules that are installed on all Debian systems).

    To check if a particular module is installed, you can use the perldoc command:

    • perldoc -l Foo::Bar prints out the full path to the module
    • perldoc -m Foo::Bar displays the contents of the module file

    If you want to see all the modules available given your current search path, try the following short script. This script works on both Win and *nix:

    use strict; use warnings; use File::Find; my @aModules; foreach my $sDir (@INC) { my $crFind = sub { my $sModule = substr($File::Find::name, length($sDir)+1); push(@aModules, $sModule) if (($sModule =~ s/\.pm$//) || ($sModule =~ /\.pl$/)); }; find($crFind, ("$sDir/")) if -d $sDir; }; print '' . join("\n", sort @aModules) . "\n";

    Note: the main difference between oko1's solution and mine is that oko1 provides support for filtering your module list with regexes but does not sort modules or list .pl files. The solution above does not support regex selection but does sort modules and list .pl files.

    Best, beth

    Update: fixed cut&paste error in script.

    Update: eliminated warnings for missing @INC dirs; insured directory name is terminated with "/" so that File::Find doesn't think directory names with dots (e.g. /usr/share/perl/5.8) are files and skip them -silly File::Find) - with thanks to oko1 whose code sample below alerted me to these problems. Also added note comparing oko1 solution below and this solution.

      it will not list core modules or ...
      'm Perl'

        The behavior of m Perl is installation dependent. On Debian, for example, anything installed by apt-get (i.e. core and vendor modules) is managed by dpkg, rather than ExtUtils, so m Perl followed by d all or f all lists nada - see here

        Best, beth

Re: perl modules
by oko1 (Deacon) on Mar 05, 2009 at 23:13 UTC

    Here's a solution that I cribbed from Randal Schwartz years ago and modified to my own tastes:

    #!/usr/bin/perl -w use strict; use File::Find; my $re = shift || "."; find sub { return unless my ($x) = $File::Find::name =~ m{\./(.*\.pm)$}; $x =~ s,/,::,g; print "$x\n" if /\Q$re\E/i; }, map "$_/.", grep -d && /^[^.]/, @INC;

    If you just invoke it by name, you get the entire list of installed modules. If you specify a regex as an argument, you'll get only the modules that match the regex (case-insensitive). I use it pretty regularly.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
Re: perl modules
by sundialsvc4 (Abbot) on Mar 06, 2009 at 01:03 UTC

    I freely admit that I am “thinking Linux” here, but what I do is to use the cpan command and say:   r.

    Having said that... it is well worth your time to issue the command perl -V (note the upper-case "V"...) and to truly learn the reasons and purposes of Perl's @INC array. (“It all makes sense, really,” ... elegant sense, even ... but it's not always obvious.)

    As you will see when you issue the command listed above, Perl looks in certain places, in a certain well-defined sequence, to find anything that it is looking for. This list (called @INC) starts with entries that are hard-coded into Perl (when it is compiled...) and can be added-to in several well-defined ways. “If it's on that list... it's available. If not, it's not there.”

Re: perl modules
by Anonymous Monk on Mar 05, 2009 at 21:12 UTC
    Google "perl modules are installed on my computer"
      And the winner is this.
      []s, HTH, Massa (κς,πμ,πλ)
Re: perl modules
by ramrod (Curate) on Mar 05, 2009 at 21:22 UTC
    Well, it's a shot in the dark - but if you got started with Perl the same way I did, then you installed Active Perl.

    In that case all you would need to do is type "ppm" at the command prompt, and CTRL+2 will let you view/search the installed Perl modules on your machine.

    But, that's just a shot in the dark. A little more commentary next time would yield much more beneficial answers. Or you could try asking a question or two in the chatterbox.

      1) I googled to find the answer. As per the directions I got, I typed "instmodsh" on the command line (Its for unix and Im using windows), and I got following output. Is there any specific command for windows ?

      C:\perlfiles>instmodsh
      Available commands are:
      l - List all installed modul
      m <module> - Select a module
      q - Quit the program
      cmd? l
      Installed modules are:
      ActivePerl::Config
      ActivePerl::DocTools
      ActivePerl::PPM
      ActiveState::RelocateTree
      ActiveState::Scineplex
      ActiveState::Utils
      Archive::Tar
      Archive::Zip
      Compress::Zlib
      DBD::SQLite
      DBI
      Data::Dump
      Digest::HMAC
      Digest::MD2
      Digest::MD4
      Digest::SHA1
      File::CounterFile
      Font::AFM
      HTML-Tree
      HTML::Parser
      HTML::Tagset
      IO::String
      IO::Zlib
      LWP
      MD5
      MIME-Base64-Scripts
      Math::BigInt::FastCalc
      Perl
      SOAP::Lite
      Tcl
      Term::ReadKey
      Term::ReadLine::Perl
      Text::Autoformat
      Text::Reform
      Tk
      Tkx
      URI
      Unicode::String
      Win32::AuthenticateUser
      XML::Parser
      XML::Simple
      libwin32

      How to check details of these packages ?
      How come I dont see CGI.pm in here. When I type "perldoc cgi.pm", I get to see details. How can we check what subroutines are available in each module ?

      2)I typed ppm on cmd prompt and I got a separate console opening up as "perl package manager" , with names of different packages in it. When I click on different packages, it does not open. So how to check these packages ?