#!/usr/bin/perl -w use strict; # findModules.pl- is for finding modules on a machine - based upon work # From: Jaimee Spencer # Date: Wed Apr 17, 2002 09:24:35 US/Pacific # To: beginners@perl.org # Subject: RE: How to check installed Modules in perl # list all of the perl modules installed - by using the File::Find # trick that Jaimee offered - but then then them all down so that we # wind up with only one sorted list - and not all of the various bits and # bobs of things that could be in the inventory more than once.... use File::Find ; my %incHash; my @modules = (); for (@INC) { my $dir = $_; $incHash{ $dir } = 1 if ( -d $dir and $dir !~/^\.$/); # no Dot Dir Hunting } my @The_Inc_We_Use =sort{ $b cmp $a }(keys(%incHash)); foreach my $dir (@The_Inc_We_Use) { find(\&wants,$dir); } sub wants { if (-d && /^[a-z]/) { $File::Find::prune = 1 ; return } return unless /\.pm$/ ; my $fullPath = "$File::Find::dir/$_"; $fullPath =~ s!\.pm$!!; $fullPath =~ s#/(\w+)$#::$1# ; push(@modules, $fullPath); # stash for post processing after find } my %list = (); foreach my $PM (@modules) { foreach my $dir (@The_Inc_We_Use) { if ( $PM =~ m!$dir! ) { $PM =~ s!^$dir!!; # we need to Know WHERE? Why? $PM =~ s/^([\/:]+)//; # kill any prefatory Gunge foo.pm in $LIB $PM =~ s#(\/)#::#; # fore the FOO::BAR::BAZ vice FOO/BAR::BAZ $list{ $PM} = 1; # the poor boys quick sort last; } } } print "where do you want to write the results to?"; my $out=; open OUT, "> $out"; print OUT "$_\n" foreach( sort(keys(%list)));