使用CPAN安装Perl模块

使用CPAN安装Perl模块

5911人阅读 评论(1) 收藏 举报
 

Perl到了第五版增加了模块的概念,用来提供面向对象编程的能力。这是Perl语言发展史上 
的一个里程碑。此后,广大自由软件爱好者开发了大量功能强大、构思精巧的Perl模块,极大地 
扩展了Perl语言的功能。CPAN(Comprehensive Perl Archive Network)是internet上Perl模块 
最大的集散地,包含了现今公布的几乎所有的perl模块。 

    几个主要的CPAN站点有: 
    国内:ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN 
          http://cpan.qz.fj.cn/ 
    国外:http://www.cpan.org/ 
          http://www.perl.com/CPAN-local/ 

    我在这里介绍一下各种平台下perl模块的安装方法。以安装DBI模块为例。 

1、Linux/Unix下的安装方法: 

    Linux/Unix下安装Perl模块有两种方法:手工安装和自动安装。第一种方法是从CPAN上下载 
您需要的模块,手工编译、安装。第二种方法是联上internet,使用一个叫做CPAN的模块自动完 
成下载、编译、安装的全过程。 

a、手工安装的步骤: 

从CPAN下载了DBI模块1.13版的压缩文件DBI-1.13.tar.gz,假设放在/usr/local/src/下。 
cd /usr/local/src 
解压缩这个文件: 
tar xvzf DBI-1.13.tar.gz 
这时会新建一个DBI-1.13的目录。 
cd DBI-1.13 

生成makefile: 
perl Makefile.PL 
建立模块 
make 
测试模块 
make test 
如果测试结果报告“all test ok”,您就可以放心地安装编译好的模块了。安装模块前,先要 
确保您对perl5安装目录有可写权限(通常以su命令获得),执行: 
make install 

现在,写个程序试试吧。 

#!/usr/bin/perl -w 
use strict; 
use DBI; 
..

    上述步骤适合于Linux/Unix下绝大多数的Perl模块。可能还有少数模块的安装方法略有差别, 
所以最好先看看安装目录里的README或INSTALL。另外,上述过程是针对动态链接的Perl编译 
器(所有Linux下预安装的Perl都是动态链接的),如果您在使用一个静态链接的Perl,您需要将 
新的模块静态链接到perl编译器中,可能还需要重启机器。

b、使用CPAN模块自动安装: 

安装前需要先联上线,并且您需要取得root权限。 
perl -MCPAN -e shell 
初次运行CPAN时需要做一些设置,如果您的机器是直接与internet相联(拨号上网、专线,etc.), 
那么一路回车就行了,只需要在最后选一个离您最近的CPAN镜像站点。例如我选的是位于国内的 
中国自由软件库ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN 。否则,如果您的机器 
位于防火墙之后,还需要设置ftp代理或http代理。 

获得帮助 
cpan>h 

列出CPAN上所有模块的列表 
cpan>m 

安装模块 
cpan>install DBI 
自动完成DBI模块从下载到安装的全过程。 

退出 
cpan>q 

2、Win32下的安装方法: 

    在Win32下,建议使用ActiveState的Perl for Win32,即ActivePerl。ActivePerl的主页在: 
http://www.activestate.com/ 。在Win32下,最好也使用专门为ActivePerl定制的Perl模块。从 
CPAN下载的Perl模块不能很好地在ActivePerl下使用。类似于CPAN模块,ActiveState也开发 
了一个自动安装工具叫做PPM(Perl Package Manager)。 

最通常的安装方法是: 
首先联上线 
在dos命令行下启动ppm 
ppm 

获得帮助 
PPM>h 

列出ActiveState站点上所有为Perl模块的清单。 
PPM>search 

安装模块 
PPM>install DBI 
自动完成DBI模块从下载到安装的全过程。 

退出 
PPM>q 

如果您的机器位于防火墙之后,通过http代理上网,那么可以使用下面的方法。 

对于老的基于perl 5.005的ActivePerl版本(ActivePerl 522以下版本,不包括ActivePerl 522),从 
http://www.ActiveState.com/ppmpackages/5.005/zips/下载您需要的Perl模块,例如DBI.zip。 
将其解压缩在C:/TEMP/DBI下 
cd /TEMP/DBI 
ppm install DBI.PPD 

最新的基于perl 5.6的ActivePerl版本(ActivePerl 613及以上版本)的安装方法略有不同。安 
装ActivePerl 613前需要先安装Microsoft的Windows Installer。 
Windows Installer从这里下载: 
http://activestate.com/download/contrib/Microsoft/9x/InstMsi.exe 
ActivePerl 613从这里下载: 
http://activestate.com/download/ … ePerl-5.6.0.613.msi 

对于基于perl 5.6的ActivePerl版本,从 
http://www.activestate.com/PPMPackages/5.6/ 
下载您需要的Perl模块的安装描述文件,例如DBI.PPD 
安装模块前需要先联上线 
ppm install DBI.PPD。 

If you are already familiar with installing CPAN modules, go-perl isno different from any other. If you aren’t, you may wish to experimentnow.

Try typing the following:

perl -MCPAN -e shell
install GO::Parser

The following may also work:

cpan GO::Parser

If this is the first time using the CPAN installer, you will beasked a barrage of questions. You are best to answer with the defaults– you can always change this later.

If you do NOT have access to the system-wide perl directories onyour system (these will typically be in /Library or /usr/local), thenyou should either get some help setting up CPAN for use with yoursystem, OR you should follow an alternate protocol below. (You may wishto modify the value of PREFIX to ~ in the CPAN setup, as detailed inprotocol III)

If you are on OS X you may need to do this:

sudo cpan GO::Parser

Providing you do have write-access to these directories, the abovecommands should hopefully go smoothly. When installing go-perl, you maybe asked if you wish to also install Data::Stag and IO::String – youshould answer yes

After this, you should be ready to use go-perl! The scripts shouldbe in your path and the libraries should be in the standard place. Youmay wish to start by trying “map2slim” or “go2obo_xml”

There are certain applications that require additional third-partymodules. All these are available from CPAN, and can be installed in theabove manner. For example, if you try and use the go-filter-subset.plscript to generate a PNG image of an ontology subgraph, the system willcomplain you do not have the module “GraphViz” installed. To installthis, simply type:

perl -MCPAN -e shell
install GraphViz

Depending on what you use go-perl for, you may not ever need to install other CPAN modules

 

Trackback : http://wanguan2000.blog.ubuntu.org.cn/2009/02/12/%E4%BD%BF%E7%94%A8cpan%E5%AE%89%E8%A3%85perl%E6%A8%A1%E5%9D%97/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值