Re: Checking for modules
by edan (Curate) on Jul 16, 2003 at 14:40 UTC
|
perl -e 'use Module;'
If it complains, then you don't have it. That should work even on NT.
-- 3dan | [reply] [Watch: Dir/Any] [d/l] |
Re: Checking for modules
by mattriff (Chaplain) on Jul 16, 2003 at 14:42 UTC
|
There are lots of ways to do it, but one quick way
would be:
perl -MData::Dumper -e ''
Data::Dumper being the module checked for in this case. That
should work in UNIX, and at least works on Win ME from a DOS
prompt, as well.
- Matt Riffle | [reply] [Watch: Dir/Any] |
(jeffa) Re: Checking for modules
by jeffa (Bishop) on Jul 16, 2003 at 15:09 UTC
|
I am strictly a Linux user, but surely perldoc
will work on NT as well:
perldoc Foo::Bar
is the least amount of characters i can think of to see if
a module is installed on the box in question.
UPDATE:
Ahhh ... haven't been bitten by that yet Aristotle ... but
i do believe you. Maybe i should have said:
[root@localhost /root]# cpan
cpan shell -- CPAN exploration and modules installation (v1.71)
ReadLine support enabled
cpan> install Foo::Bar
instead ;) (yes yes ... this won't work with ppm, but you
get the gist ... just install it, chances are if it
is already installed, it could use an upgrade).
Thanks once again Aristotle (he watches my
back ;))
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
Re: Checking for modules
by jmcnamara (Monsignor) on Jul 16, 2003 at 16:00 UTC
|
Here are some simple Unix and Windows one-liners that check whether a module is installed. They return 1 or 0 accordingly:
(Unix) perl -le 'print 0 + eval "require $ARGV[0]"' Some::Module
(Win) perl -le "print 0 + eval qq(require $ARGV[0])" Some::Module
Or as a program with clearer output:
#!/usr/bin/perl -wl
for my $module (@ARGV) {
print "$module is ",
eval "require $module" ? "" : "not ",
"installed.";
}
__END__
$ perl installed.pl Parse::RecDescent Parse::RecklessDescent
Parse::RecDescent is installed.
Parse::RecklessDescent is not installed.
--
John.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Checking for modules
by nega (Scribe) on Jul 16, 2003 at 16:01 UTC
|
If you wanted check from within your script/program you could try something similar to the following (which is from Chapter 12 of the Perl Cookbook):
BEGIN {
unless (eval "use $mod") {
warn "couldn't load $mod: $@";
}
}
I find this useful for version checking modules and throwing out meaningful errors to users, if they're lacking a particular module. | [reply] [Watch: Dir/Any] [d/l] |
Re: Checking for modules
by DigitalKitty (Parson) on Jul 16, 2003 at 17:46 UTC
|
| [reply] [Watch: Dir/Any] |
|
Well, it sure helped me! This script *rocks*! I have a bunch of websites and I'm always after information on installed modules and settings. This little sweetheart just laid it all out for me.
THANK YOU!
Jim aka RyuMaou
| [reply] [Watch: Dir/Any] |
Re: Checking for modules
by blue_cowdawg (Monsignor) on Jul 16, 2003 at 18:56 UTC
|
Here is a sub from a CGI script that I install on new
sites that I am writing CGI for. The list of modules I
check for of course changes with the requirements of what
I expect to write.
sub module_inventory {
my @modules=qw/
Net::Ping Net::LDAP HTML::Template
GnuPG::Fingerprint GnuPG::UserID GnuPG::Tie::ClearSign
Date::Range Date::Manip Date::Calc Calendar::Simple
CGI::Log CGI::LogCarp CGI::Cookie CGI::CoockieSerial
CGI::EZForm CGI::FormBuilder GD CGI::Graph
HTML::Calendar::Simple HTML::CalendarMonth HTML::Form
HTML::TableLayout
Spreadsheet::WriteExcel
MIME::Lite MIME::Entity MIME::Tools MIME::Base64
Mail::Send Mail::Sendmail
/;
my $rstring="<table border=\"1\">";
$rstring .= Tr(th("Module"),th("Status"));
foreach my $mod(sort @modules) {
eval " use $mod; " ;
if ($@) {
$rstring .= Tr(td($mod),td(b("Not Available"),$@));
} else {
$rstring .= Tr(td($mod),td("OK"));
}
}
$rstring .="</table>";
return $rstring;
}
I wrote this thing many, many, moons ago and if I really took a hard long look at it I'd probably improve on it.
But then again... if it ain't broke... I ain't fixing it.
Peter L. Berghold | Brewer of Belgian Ales |
Peter@Berghold.Net | www.berghold.net |
Unix Professional |
| [reply] [Watch: Dir/Any] [d/l] |
Re: Checking for modules
by artist (Parson) on Jul 16, 2003 at 15:33 UTC
|
perldoc -l Module::Name gives you the exact location of the module on Unix and NT systems.
artist | [reply] [Watch: Dir/Any] [d/l] |
|
$ perldoc -l Term::Shell
/usr/lib/perl5/site_perl/5.8.0/Term/Shell.pod
It gives you the location of the POD, which may or may not be the module itself.
Makeshifts last the longest. | [reply] [Watch: Dir/Any] [d/l] |
|
-l file name only
Display the file name of the module found.
Now, I have used it all the time. I didn't know otherwise.
artist | [reply] [Watch: Dir/Any] |
Re: Checking for modules
by jmanning2k (Pilgrim) on Jul 16, 2003 at 18:47 UTC
|
I have a perlwhich script (written in perl, of course), to which you can give a module name, and it will search @INC for a module by that name.
This gives you the path to the library, and if it is installed in your @INC path or not.
I can post it to snippets if you think it would be helpful...
EDIT: Posted here: perlwhich - find which perl module you are using (and more). And some (better?) ones have been posted here: whichpm.
Sample Output:
>~/bin/perlwhich -m 'Storable'
/util/lib/perl5.8/lib/5.8.0/alpha-dec_osf -- Storable (2.04) - persist
+ence for Perl data structures
/util/lib/perl5.8/lib/5.8.0 -- Memoize::Storable (0.65) - store Memoiz
+ed data in Storable database
| [reply] [Watch: Dir/Any] [d/l] |
|
Please post your script. thanks
| [reply] [Watch: Dir/Any] |