Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check for Module

Posted on 2000-05-04
4
Medium Priority
?
220 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 200 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 85

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

916 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