DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Different Ways To List Installed Perl Modules

11.03.2009
| 4826 views |
  • submit to reddit
        
perl -MExtUtils::Installed -e 'print $_,$/ for ExtUtils::Installed->new()->modules();'

Or more thoroughly:

#!/usr/bin/perl -w

use strict;
use ExtUtils::Installed;
my $inst = ExtUtils::Installed->new();
print map "$_\n", @ARGV
       ? map $inst->files($_), @ARGV
       : $inst->modules();

This is a manual way:

for DIR in `perl -e 'print join $/, @INC'`; do
find $DIR -name "*.pm"|perl -pe "s|$DIR/||;s|/|::|g;s/\.pm$//;"
done uniq

or other things based on:

find $(perl -e 'print join $/, @INC;') -name "*.pm"

like:

#!/usr/bin/perl
# list all of the perl modules installed
use File::Find ;
for (@INC) { find(\&modules,$_) ; }

sub modules
{
        if (-d && /^[a-z]/) { $File::Find::prune = 1 ; return }
        return unless /\.pm$/ ;
        my $fullPath = "$File::Find::dir/$_";
        $fullPath =~ s!\.pm$!!;
        $fullPath =~ s#/(\w+)$#::$1# ;
        print "$fullPath \n";
}