Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

List of installed modules

by fundflow (Chaplain)
on Dec 28, 2000 at 21:30 UTC ( #48643=perlquestion: print w/ replies, xml ) Need Help??
fundflow has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Is there a way to print a list of all the installed modules on the system?

It should probably work by searching the @INC directory list.

This will ease the headache of using scripts across several machines here.

Thanks.

Comment on List of installed modules
Download Code
Re: List of installed modules
by OeufMayo (Curate) on Dec 28, 2000 at 21:54 UTC

    Is there a simple way to search Perlmonks.org?

    Yes! And if you type 'Installed modules' on the search box, you'll find that this node already answered the question.

    <kbd>--
    PerlMonger::Paris(http => 'paris.pm.org');</kbd>
Re: List of installed modules
by lemming (Priest) on Dec 28, 2000 at 21:54 UTC
    use warnings; use strict; use File::Find; foreach my $dir (@INC) { File::Find::find (\&wanted,"$dir"); } sub wanted { if ($File::Find::name =~ /\.pm$/) { print "$File::Find::name\n"; } }
    Hmmm. I could do better. Instead of the full path, we should print the module as it would be called and print the version number if found.
    Update: Forgot to search perlmonks. Did a search on cpan and it was quicker to whip out the above code.
      the code's already been posted, and the other solutions are obviously better, but i wanted to do more useless one-lining...

      #!/usr/local/bin/perl -w use strict; use File::Find; find { wanted => sub {print if /\.pm$/}, no_chdir=>1} $dir foreach my +$dir (@INC);
      hmmm, there are probably subdirectories in @INC that we've already searched since it recursively goes through the directories. Which would be faster: a search through all the directories using find or a prune using a hash to not re-search directories we've been through? The following is untested (ok, so was the above code), but it's an example...

      # same guidelines as above, use strict and that ilk my %been_at; sub wanted { return if $been_at{$dir}; $been_at{$dir} = 1; print if /\.pm$/; } find { wanted => \&wanted, no_chdir => 1 } $dir foreach my $dir (@INC) +;
      So the question i now have is would it be faster to make a hash or recurse possibly the same directories? i don't think this example is a significantly large enough search space to make much of a difference, but if it were would the latter method be faster? i think so but maybe someone can point out something i'm missing...


      Also while i'm at it, is no_chdir a hit to performance when recursing directories? Is it better to allow it to change directories? Please comment, i'm still new to File::Find.

      jynx

Re: List of installed modules
by cianoz (Friar) on Dec 28, 2000 at 22:13 UTC
    i use this little script to check installed modules (and if they need to be updated)
    requires CPAN.pm
    #!/usr/bin/perl -w use CPAN; for my $mod (CPAN::Shell->expand("Module","/./")){ next unless $mod->inst_file; print $mod->id, '(', $mod->inst_version, ') '; unless($mod->uptodate()) { print "\t\t#( V. ",$mod->cpan_version, " available on CPAN +)"; } print "\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://48643]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-12-28 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls