How do I get a list of installed CPAN modules?

后端 未结 29 2103
盖世英雄少女心
盖世英雄少女心 2020-12-04 07:41

Aside from trying

perldoc 

individually for any CPAN module that takes my fancy or going through the file system and loo

29条回答
  •  情深已故
    2020-12-04 07:41

    To walk through the @INC directory trees without using an external program like ls(1), one could use the File::Find::Rule module, which has a nice declarative interface.

    Also, you want to filter out duplicates in case previous Perl versions contain the same modules. The code to do this looks like:

    #! /usr/bin/perl -l
    
    use strict;
    use warnings;
    use File::Find::Rule;
    
    my %seen;
    for my $path (@INC) {
        for my $file (File::Find::Rule->name('*.pm')->in($path)) {
            my $module = substr($file, length($path)+1);
            $module =~ s/.pm$//;
            $module =~ s{[\\/]}{::}g;
            print $module unless $seen{$module}++;
        }
    }
    

    At the end of the run, you also have all your module names as keys in the %seen hash. The code could be adapted to save the canonical filename (given in $file) as the value of the key instead of a count of times seen.

提交回复
热议问题