Prev: FAQ 1.12 What's the difference between "perl" and "Perl"?
Next: FAQ 2.5 I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/... failed. How do I make it work?
From: PerlFAQ Server on 8 Apr 2010 06:00 This is an excerpt from the latest version perlfaq3.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 3.4: How do I find which modules are installed on my system? From the command line, you can use the "cpan" command's "-l" switch: $ cpan -l You can also use "cpan"'s "-a" switch to create an autobundle file that "CPAN.pm" understands and can use to re-install every module: $ cpan -a Inside a Perl program, you can use the "ExtUtils::Installed" module to show all installed distributions, although it can take awhile to do its magic. The standard library which comes with Perl just shows up as "Perl" (although you can get those with "Module::CoreList"). use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); my @modules = $inst->modules(); If you want a list of all of the Perl module filenames, you can use "File::Find::Rule": use File::Find::Rule; my @files = File::Find::Rule-> extras({follow => 1})-> file()-> name( '*.pm' )-> in( @INC ) ; If you do not have that module, you can do the same thing with "File::Find" which is part of the standard library: use File::Find; my @files; find( { wanted => sub { push @files, $File::Find::fullname if -f $File::Find::fullname && /\.pm$/ }, follow => 1, follow_skip => 2, }, @INC ); print join "\n", @files; If you simply need to quickly check to see if a module is available, you can check for its documentation. If you can read the documentation the module is most likely installed. If you cannot read the documentation, the module might not have any (in rare cases): $ perldoc Module::Name You can also try to include the module in a one-liner to see if perl finds it: $ perl -MModule::Name -e1 -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod.
From: Peter Billam on 8 Apr 2010 06:20 On 2010-04-08, PerlFAQ Server <brian(a)theperlreview.com> wrote: > 3.4: How do I find which modules are installed on my system? > From the command line, you can use the "cpan" command's "-l" switch: > $ cpan -l Hmm... I'm running up-to-date debian squeeze, /usr/bin/cpan script version 1.9, CPAN.pm version 1.9402, and when I try that I just get: box8> cpan -l Unknown option: l Nothing to install! :-( Am I doing something wrong ? Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
From: brian d foy on 8 Apr 2010 15:28 [[ This message was both posted and mailed: see the "To," "Cc," and "Newsgroups" headers for details. ]] In article <slrnhrrbfj.3mr.peter(a)box8.pjb.com.au>, Peter Billam <peter(a)www.pjb.com.au> wrote: > On 2010-04-08, PerlFAQ Server <brian(a)theperlreview.com> wrote: > > 3.4: How do I find which modules are installed on my system? > > From the command line, you can use the "cpan" command's "-l" switch: > > $ cpan -l > > Hmm... I'm running up-to-date debian squeeze, > /usr/bin/cpan script version 1.9, CPAN.pm version 1.9402, Check that you are using the latest cpan client. It's in App::Cpan on CPAN.
From: Steve M on 8 Apr 2010 17:11 On 4/8/2010 3:00 AM, PerlFAQ Server wrote: > This is an excerpt from the latest version perlfaq3.pod, which > comes with the standard Perl distribution. These postings aim to > reduce the number of repeated questions as well as allow the community > to review and update the answers. The latest version of the complete > perlfaq is at http://faq.perl.org . > > -------------------------------------------------------------------- > > 3.4: How do I find which modules are installed on my system? > > From the command line, you can use the "cpan" command's "-l" switch: > > $ cpan -l > > You can also use "cpan"'s "-a" switch to create an autobundle file that > "CPAN.pm" understands and can use to re-install every module: > > $ cpan -a > > Inside a Perl program, you can use the "ExtUtils::Installed" module to > show all installed distributions, although it can take awhile to do its > magic. The standard library which comes with Perl just shows up as > "Perl" (although you can get those with "Module::CoreList"). > > use ExtUtils::Installed; > > my $inst = ExtUtils::Installed->new(); > my @modules = $inst->modules(); > > If you want a list of all of the Perl module filenames, you can use > "File::Find::Rule": > > use File::Find::Rule; > > my @files = File::Find::Rule-> > extras({follow => 1})-> > file()-> > name( '*.pm' )-> > in( @INC ) > ; > > If you do not have that module, you can do the same thing with > "File::Find" which is part of the standard library: > > use File::Find; > my @files; > > find( > { > wanted => sub { > push @files, $File::Find::fullname > if -f $File::Find::fullname&& /\.pm$/ > }, > follow => 1, > follow_skip => 2, > }, > @INC > ); > > print join "\n", @files; > > If you simply need to quickly check to see if a module is available, you > can check for its documentation. If you can read the documentation the > module is most likely installed. If you cannot read the documentation, > the module might not have any (in rare cases): > > $ perldoc Module::Name > > You can also try to include the module in a one-liner to see if perl > finds it: > > $ perl -MModule::Name -e1 > > > > -------------------------------------------------------------------- > > The perlfaq-workers, a group of volunteers, maintain the perlfaq. They > are not necessarily experts in every domain where Perl might show up, > so please include as much information as possible and relevant in any > corrections. The perlfaq-workers also don't have access to every > operating system or platform, so please include relevant details for > corrections to examples that do not work on particular platforms. > Working code is greatly appreciated. > > If you'd like to help maintain the perlfaq, see the details in > perlfaq.pod. Often times I'm working on a web site for someone where I do not have command line access, only web browser access, and I wish to check for specific modules that are a little off the beaten path, such as Spreadsheet::WriteExcel. In such a case, the above examples are perhaps not as 'to the point' as a reader might wish. I use a different (simpler?) method than any shown above, and wonder if it might be a good concept to include in the above options. In essence I run something like below. ********* To construct a simple CGI script to test for module availability when the command line is not available, but you do have CGI capability: #!/usr/bin/perl use warnings; $! = 1; print "Content-type: text/html\n\n"; print qq~Testing for availability of Perl Modules<br><br>\n~; my @test_list = ( 'CGI', 'DBI', 'Spreadsheet::WriteExcel', 'Spreadsheet::ParseExcel', ); for( @test_list ){ print qq~$_: ~; eval "use $_; 1" ? ( print 'Available' ) : ( print 'MISSING!!!' ); print "<br>\n"; } exit; ************* I'm thinking someone trying to get their feet wet with CGI scripts might find the above example to be more in line with what they can understand or use and what they probably have available. Or maybe not. :-) \s -- "There is no use in your walking five miles to fish when you can depend on being just as unsuccessful near home." M. Twain
From: Uri Guttman on 8 Apr 2010 18:06
>>>>> "SM" == Steve M <stevem_clipthis_(a)clubtrout.com> writes: SM> #!/usr/bin/perl SM> use warnings; why not strict too? SM> $! = 1; huh? i think you meant $| = 1. and that will not have any real affect with such a short output and also with the buffering done by the server. SM> print "Content-type: text/html\n\n"; SM> print qq~Testing for availability of Perl Modules<br><br>\n~; why are you using alternate quote chars when there are no quote chars in the string? and if you do use alternate quotes, the best ones are the paired chars. i use (and PBP recommends it too) q{} or qq{}. SM> my @test_list = ( SM> 'CGI', SM> 'DBI', SM> 'Spreadsheet::WriteExcel', SM> 'Spreadsheet::ParseExcel', SM> ); SM> for( @test_list ){ SM> print qq~$_: ~; no need for alternate quotes there. SM> eval "use $_; 1" ? ( print 'Available' ) : ( print 'MISSING!!!' ); SM> print "<br>\n"; and that could all be done in one print: print "$_: ", ( eval "use $_; 1" ) ? 'Available' : 'MISSING!!!', "<br>\n"; a lot easier to see what you are doing that way. and no need for all those extra print calls. also it removes the side effect thing inside ?: which is bad style. ?: is meant to return a value, not choose which side effect to execute. but your concept is valid only if you have a lousy web service without a shell. it is easier to switch services than to hack code only after you ftp it there! uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- |