Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What modules do I have installed?

Installing Modules

What modules do I have installed?

by  missbarbell  Posted    (Edited  )
Every so often someone asks how to get a difinitive list of the Perl modules on their system. There are a few ways of doing it, but most are incomplete. You can use your local automatic installer (eg PPM) but they don't generally give you the full picture.

The piece of code below looks at what is really available to you, by using the @INC list. This contains the paths (and code blocks) to where perl can go and find the additional libraries when you ask it to 'use' or 'require' one.

In addition the following will also take into account the fact that some module libraries can contain more than one package :)

Code:
#!/usr/bin/perl -w
use strict;

use File::Find;

my %modlist;
find(\&print_package, @INC);

sub print_package {                                   
    if ($File::Find::name =~ /\.pm$/) {
        return unless open(PM, $File::Find::name);
        foreach (<PM>) {
            if (/^ *package +(\S+);/) {
                $modlist{$1}=1;
            }
        }
        close(PM);
    }
}

print "$_\n"    for(sort keys %modlist);
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top