Solved

Check for Module

Posted on 2000-05-04
4
185 Views
Last Modified: 2010-03-05
Is it possible to check if a module is installed and if so set $test = 1;

I want to check for LWP::Simple
0
Comment
Question by:mmcw
4 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 50 total points
ID: 2779178
Here is a very simple solution. I know that the ExtUtils::MakeMaker has functions to detect if modules are installed. You can also specify pre-requisites (ie other modules) needed for your own module.

$module_installed = 0;
$module_name = "LWP/Simple.pm";
foreach $dir ( @INC )
{
   ( -e "$dir/$module_name" ) and $module_installed = 1;
}
if ( $module_installed )
{
   print("$module_name is installed\n");
}
else
{
   print("$module_name is not installed\n");
}
0
 

Author Comment

by:mmcw
ID: 2779773
An other little question:
 What will happen if you try to use a module that is not installed:
example: use LWP::Simple;
0
 
LVL 84

Expert Comment

by:ozo
ID: 2779936
eval{ require LWP::Simple };
 $test = !$@;
 die $@ if $@;
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2782206
You will get an error saying that the module cannot be dound in any of the paths in the @INC array.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question