Perl模块的维护
? 我们在使用Perl时会用到各种各样的模块,比如,我们常用的DBI、DBD等等。 ? 那么,我们怎样去维护它呢? ? 1. 下载 ? 我们使用搜索引擎(bing or google,Not recommend baidu),输入“模块名 cpan”即可。 ? 比如,我们要安装"Encode::Locale"模块, ? 在必应的搜索结果(红色方框圈的既是): ? 在谷歌的搜索结果(红色方框圈的既是): ? 点击链接,选择相关版本即可(一般情况下,我们选择最新的版本)。 ? 2. 安装 ? 下载完模块后,我们解压缩、安装。 ? $tar zxvf xxx.tar.gz ? $cd xxx ? $perl Makefile.PL ? $make ? $make test ? $make install ? 注意:有的tar.gz文件会显示“his does not look like a tar archive”提示。 ? ? ? ? ? ? ? ?这样的文件(tar.gz)是只包含tar文件的。需要进行两步操作:a)gzip -d xxxx.tar.gz b)tar -xf xxxx.tar ? 3. 查看已安装模块 ? 我们需要写一个简单的程序来完成。 ? 程序代码如下所示: ? testPM.pl #!/usr/bin/env perl # pmlist - report modules which are installed on your machine # Author: Hinemos use strict; use warnings; use ExtUtils::Installed; use UNIVERSAL::require; use Getopt::Long; GetOptions( verbose => my $verbose ); my @installed_modules = ExtUtils::Installed->new->modules; for my $module (@installed_modules) { print $module; if ($verbose) { if ($module eq 'Perl') { print "t$^V"; } else { # suppress some 'inevitable' warnings local $SIG{__WARN__} = sub { }; $module->require; no strict 'refs'; my $v = ${$module . '::VERSION'}; printf "t%s",defined $v ? $v : 'undetectable' ; } } print "n"; } 执行的结果(我的机器)如下: Class::Factory::Util Class::Inspector Config::General DBD::mysql DBI Encode::Locale File::Listing File::ShareDir (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |