top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Perl: How do I find which modules are installed on my system?

+1 vote
484 views
Perl: How do I find which modules are installed on my system?
posted Apr 29, 2014 by Anuradha Tabyal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

From the command line, you can use the cpan command's -l switch:

$ cpan -l

You can also use cpan 's -a switch to create an autobundle file that CPAN.pm understands and can use to re-install every module:

$ cpan -a

Inside a Perl program, you can use the ExtUtils::Installed module to show all installed distributions, although it can take awhile to do its magic. The standard library which comes with Perl just shows up as "Perl" (although you can get those with Module::CoreList).

use ExtUtils::Installed;
my $inst    = ExtUtils::Installed->new();
my @modules = $inst->modules();

If you want a list of all of the Perl module filenames, you can use File::Find::Rule:

use File::Find::Rule;
my @files = File::Find::Rule->
    extras({follow => 1})->
    file()->
    name( '*.pm' )->
    in( @INC )
    ;

If you do not have that module, you can do the same thing with File::Find which is part of the standard library:

 use File::Find;
    my @files;
    find(
        {
        wanted => sub {
            push @files, $File::Find::fullname
            if -f $File::Find::fullname && /\.pm$/
        },
        follow => 1,
        follow_skip => 2,
        },
        @INC
    );
    print join "\n", @files;

If you simply need to check quickly to see if a module is available, you can check for its documentation. If you can read the documentation the module is most likely installed. If you cannot read the documentation, the module might not have any (in rare cases):

  $ perldoc Module::Name

You can also try to include the module in a one-liner to see if perl finds it:

$ perl -MModule::Name -e1

(If you don't receive a "Can't locate ... in @INC" error message, then Perl found the module name you asked for.)

answer Apr 30, 2014 by Simranjeet Singh
Similar Questions
+1 vote

I have a Linux machine and windows machine, I need to run a GUI of Linux machine on the windows machine.
I don't want to use putty or any other software. I have to use any Perl modules to achieve this please help.

+1 vote

I need to access ClearQuest programatically using Perl. I just found ClearQuest OSLC REST API. Client is planning to use ClearQuest web 7.1.1. I read that it comes with OSLC REST API out the box.
Can someone please provide me some examples on how I can access the CQ through Perl using this API.

+1 vote

How do I find the next subnet? This should print 192.168.1.0 the second time - it errors:

#!/usr/bin/env perl

use strict;
use warnings;

use Net::IP;

my $ip = Net::IP->new('192.168.0.0/24');

print "Start ip [" . $ip->ip . "]n";
print "start mask [" . $ip->prefixlen . "]n";

$ip->set($ip->last_ip);
$ip++;
$ip->set($ip->ip . "/" . $ip->prefixlen);

print "Start ip [" . $ip->ip . "]n";
print "start mask [" . $ip->prefixlen . "]n";

## ERROR
 % ./t2.pl
Start ip [192.168.0.0]
start mask [24]

Can't call method "ip" on an undefined value at ./t2.pl line 15.

+1 vote
$ perl -le 'system "df -h"'
$ perl -le 'system "df","-h"'

Both two styles work fine. What's the difference between them and which is better usage?

...