I have made a script to intimate the admin the list of module need to be installed on machine .
I am trying to check wheather the module installed by underbelow code. The odd thing is that it is showing even installed module in the machine as not installed
#!/usr/bin/perl -w
my @module_list =('Smart::Comments','HTML::Parse');
foreach (@module_list) {
eval { require "$_" };
if (!($@)) {
print "Module Not installed : $_\n";
}
}
You need to use the string form of eval
because require
needs a bareword argument to match against the double-colon-separated form of the module name (e.g. Scalar::Util
). (If it's not a bareword, then it needs to be a relative path, e.g. 'Scalar/Util.pm'
)
#!/usr/bin/perl
use strict;
use warnings;
my @module_list = ('Scalar::Util', 'flibble');
foreach (@module_list) {
if (!eval "require $_") {
print "Module not installed: $_\n";
}
}
There's my App::Module::Lister, which I designed as a modulino that can run as a module, a command-line utility, or a CGI script. It's a simple thing I needed for a friend who only had FTP access to a web server.
It gives you the list of everything in Perl's module search path, which I usually find easier than checking for specific modules each time. Once I have the whole list, I just look at the list.
You could check that you can load the module, but I tend to not like that because I don't want to potentially run the module's code to see if it's installed. It's usually not a problem, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With