Say you have a couple of Perl programs and you would like to know what modules are used by the programs, and may be you would also like to know what are the module versions and if they exists or not. Here is a combination of common commands to list and print module version, and print a message if the module does not exists. Code: egrep '^[\s\t]*use[ ]+[a-zA-Z:]' *.pl|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);' This will list the modules used by the .pl programs in the current directory. The next example will do a recursive search. Code: egrep -R '^[\s\t]*use[ ]+[a-zA-Z:]' *.pl|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);' Example output: Code: [root@pradeep:/var/www/cgi-bin] egrep -R '^[\s\t]*use[ ]+[a-zA-Z:]' *|cut -d ' ' -f 2|cut -d ';' -f 1|sort --unique|xargs -n 1 -I % perl -e 'eval {require %;print "% => ", $%::VERSION,"\n";}; print "\033[31mmissing %\033[0m\n" if($@);' CGI => 3.38 CGI::Carp => 1.30_01 DBI => 1.607 Data::Dumper => 2.121_08 DateTime => 0.4304 Digest::MD5 => 2.36 missing Email::Valid LWP::Simple => 5.810 LWP::UserAgent => 5.814 MIME::Base64 => 3.07 MIME::Lite => 3.022 Net::SMTP_auth => 0.08 missing PAB3::Crypt::XOR POSIX => 1.09 Parallel::ForkManager => 0.7.5 missing Slurp Enjoy! Update if you have any ideas.
ExtUtils::Installed this module is used to show all installed distributions, sample code: Code: use ExtUtils::Installed; use Data::Dumper; my ($inst) = ExtUtils::Installed->new(); my (@modules) = $inst->modules(); print Dumper \@modules; To list of all of the Perl module filenames use the File::Find module: - Example: ------- Code: use Data::Dumper; use File::Find; my @files; find( sub { push @files, $File::Find::name if -f $File::Find::name && /\.pm$/ }, @INC ); print Dumper \@files; The above code will display the all *.pm files in your system.
I'm trying to figure out how to automatically list all the modules used by a particular program. Try this, foreach (sort keys %INC) {print "$_\n"} This will give default modules used by a particular program. If you include any module other than default things that also will include in your INC hash.
*{$glob}{PACKAGE} , *{$glob}{NAME}, these are all built in variables used to find the packages used in the current Perl program