免费注册 查看新帖 |

Chinaunix

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

[PerlFAQ] How do I find which modules are installed on my system? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-29 19:49 |只看该作者 |倒序浏览
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 cna 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


仙子注曰:
山重水复疑无路,柳暗花明又一村。
方法有时很重要。

论坛徽章:
0
2 [报告]
发表于 2009-11-30 10:10 |只看该作者
我这没 -l 这个参数

$ cpan -l
Unknown option: l
Nothing to install!

$ cpan -v
/usr/bin/cpan script version 1.9, CPAN.pm version 1.9402

$ perl -v

This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP