Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I have a perl script test a bunch of modules and print out a report that they are installed or not?

Do you know where I can find something like that? It cannot be a module because that module may not be installed on the server already, so it needs to be just perl.

If you can point me in the right direction, I'd be greatly appreciated.

Thanks,
Lee

Replies are listed 'Best First'.
Re: module test
by bobf (Monsignor) on Apr 11, 2007 at 19:03 UTC

    There are several ways to do this. See perlfaq3: "How do I find which modules are installed on my system?" for a quick solution, or Super Search for others (this question is not uncommon).

    Update: the approach suggested above will generate a list of all installed modules, which you can then search to see if a particular module is installed. If you want to take a more direct approach and test each module in question without generating the list of installed modules, Best way to check for installed module will give you ideas. The short answer is to just wrap the use in an eval and test for errors.

      Thank you! I figured it out with your help. Here is what I did:
      #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard :cgi-lib); use strict; my @modules = qw( LWP::UserAgent My::Module Crypt::Blowfish Apache::Se +ssion::MySQL CGI CGI::Carp ); my ($_content, $mod); foreach $mod (@modules) { $_content .= qq~Checking "$mod"... ~; eval("use $mod"); if ($@) { $_content .= qq~$mod is NOT installed.~; $_content .= br() x 2; } else { $_content .= qq~$mod is installed.~; $_content .= br() x 2; } } print header(), start_html(-title=>"System Test"), $_content, end_html();
A reply falls below the community's threshold of quality. You may see it by logging in.