Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check the list of module installed in machine

Tags:

module

perl

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";
      }
    }
like image 712
made_in_india Avatar asked Feb 09 '12 10:02

made_in_india


2 Answers

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";
    }
}
like image 51
zgpmax Avatar answered Sep 16 '22 21:09

zgpmax


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.

like image 31
brian d foy Avatar answered Sep 19 '22 21:09

brian d foy