linux perl模块 使用,Linux下使用CPAN进行Perl模块的安装

当我们想使用某些Perl模块的时候,很可能会遇到当前系统不存在这个模块的情况,这时我们可以通过使用CPAN来对相应的模块进行获取,下面就介绍一下CPAN的使用方法。

首先,我们可以用perl -e 'use module'这个命令来检查一下系统的perl的某个模块是否可用,如

[root@localhost ~]# perl -e 'use Test::Parser'

Can't locate Test/Parser.pm in @INC (......更多报错信息自动略过) at -e line 1.

BEGIN failed--compilation aborted at -e line 1.

根据显示我们知道系统上没有Test::Parser这个模块,因此我们需要使用CPAN进行安装,因此下面我们进入CPAN。

[root@localhost ~]# perl -MCPAN -e shell

Can't locate CPAN.pm in @INC (......).

BEGIN failed--compilation aborted.

此时进入CPAN失败,原因很简单,系统没有包含CPAN,所以我们需要首先安装CPAN,方法如下(本人使用的是Fedora 8,其他系统请对号入座):

[root@localhost ~]# yum install perl-CPAN

updates-newkey  | 2.3 kB  00:00

fedora  | 2.1 kB  00:00

updates  | 2.6 kB  00:00

设置安装进程

分析安装参数的语法

解决依赖相关

-->运行处理检查

---> 包 perl-CPAN.i386 0:1.76_02-41.fc8 设置为 升级

--> 完成依赖性检查

依赖性解决

================================================================================

包  架构  版本  仓库  大小

================================================================================

正在安装:

perl-CPAN  i386  1.76_02-41.fc8  updates-newkey  129 k

Transaction Summary

================================================================================

Install  1 Package(s)

Update  0 Package(s)

Remove  0 Package(s)

总共下载大小: 129 k

确定是这样吗? [y/N]: y

下载软件包:

perl-CPAN-1.76_02-41.fc8.i386.rpm  | 129 kB  00:02

============================== Entering rpm code ===============================

运行 rpm_check_debug

运行测试事务处理

传输测试完成

事务处理测试成功

运行事务处理

正在安装  : perl-CPAN  1/1

=============================== Leaving rpm code ===============================

已安装:

perl-CPAN.i386 0:1.76_02-41.fc8

恭喜你!成功完成!

这时我们就完成了perl-CPAN的安装,再次使用刚才的命令进入CPAN。

[root@localhost ~]# perl -MCPAN -e shell

/usr/lib/perl5/5.8.8/CPAN/Config.pm initialized.

CPAN is the world-wide archive of perl resources. It consists of about

100 sites that all replicate the same contents all around the globe.

Many countries have at least one CPAN site already. The resources

found on CPAN are easily accessible with the CPAN.pm module. If you

want to use CPAN.pm, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this

question and I'll try to autoconfigure. (Note: you can revisit this

dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes]

因为是首次使用cpan所以系统需要配置一下环境参数,可以直接选择no.

cpan> reload cpan  # 更新CPAN

在完成以上步骤后,就可以用install module 来安装需要的模块了

[root@localhost ~]# cpan> install Test::Parser

如果最后显示OK的话,则该模块可以使用了,这一点可以通过第一步的命令进行检查。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值