免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7147 | 回复: 19
打印 上一主题 下一主题

如何查看已安装的模块? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 16:38 |只看该作者 |倒序浏览
perl -MCPAN -e shell
cpan>m

明显不是,返回了7W多条。

论坛徽章:
0
2 [报告]
发表于 2009-11-10 16:41 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2009-11-11 17:54 |只看该作者
原帖由 fxbird 于 2009-11-10 16:38 发表
perl -MCPAN -e shell
cpan>m

明显不是,返回了7W多条。


perldoc perlfaq3:)
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 reinstall
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

论坛徽章:
0
4 [报告]
发表于 2009-11-11 17:56 |只看该作者
perl-info

论坛徽章:
0
5 [报告]
发表于 2009-11-13 22:56 |只看该作者
原帖由 mwm5 于 2009-11-11 17:54 发表


perldoc perlfaq3

你好,根本不支持cpan -l,没有这个参数

论坛徽章:
0
6 [报告]
发表于 2009-11-13 23:09 |只看该作者
原帖由 兰花仙子 于 2009-11-10 16:41 发表
http://search.cpan.org/~yves/Ext ... tUtils/Installed.pm

按那个文章说的,下面的例子本文返回所有模块,结果却只有Perl

use ExtUtils::Installed;
   my ($inst) = ExtUtils::Installed->new();
   my (@modules) = $inst->modules();
   print "@modules";

论坛徽章:
0
7 [报告]
发表于 2009-11-13 23:11 |只看该作者
原帖由 fxbird 于 2009-11-13 23:09 发表

按那个文章说的,下面的例子本文返回所有模块,结果却只有Perl

use ExtUtils::Installed;
   my ($inst) = ExtUtils::Installed->new();
   my (@modules) = $inst->mod ...

这是不是说明除了核心模块,我什么都没安过?

论坛徽章:
0
8 [报告]
发表于 2009-11-14 17:54 |只看该作者
List installed Perl Modules in a nice table:
list-modules.7z (1.85 KB, 下载次数: 52)

论坛徽章:
0
9 [报告]
发表于 2009-11-14 18:02 |只看该作者
原帖由 fxbird 于 2009-11-13 23:09 发表

按那个文章说的,下面的例子本文返回所有模块,结果却只有Perl


# cat list.pl
use ExtUtils::Installed;
my ($inst) = ExtUtils::Installed->new();
my (@modules) = $inst->modules();
print "$_\n" for @modules;

# perl list.pl
Algorithm::Diff
AppConfig
Array::Compare
Array::Diff
Authen::SASL
Benchmark::Timer

... many others

论坛徽章:
0
10 [报告]
发表于 2009-11-14 18:15 |只看该作者

回复 #9 兰花仙子 的帖子

花仙子,用这个脚本 列出的Modules不全啊~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP