Solved

Check for Module

Posted on 2000-05-04
4
176 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 97
Perl Frameworks 1 81
Matching a random pattern with one common character 2 45
html form to write data to csv 24 97
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now