`
sealbird
  • 浏览: 568036 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

使用CPAN安装Perl模块

    博客分类:
  • perl
阅读更多
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 is no different from any other. If you aren’t, you may wish to experiment now.

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 be asked 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 on your system (these will typically be in /Library or /usr/local), then you should either get some help setting up CPAN for use with your system, OR you should follow an alternate protocol below. (You may wish to modify the value of PREFIX to ~ in the CPAN setup, as detailed in protocol 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 above commands should hopefully go smoothly. When installing go-perl, you may be asked if you wish to also install Data::Stag and IO::String – you should answer yes

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

There are certain applications that require additional third-party modules. All these are available from CPAN, and can be installed in the above manner. For example, if you try and use the go-filter-subset.pl script. to generate a PNG image of an ontology subgraph, the system will complain you do not have the module “GraphViz” installed. To install this, 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/
分享到:
评论

相关推荐

    Linux上安装Perl模块方法介绍

    Linux上安装Perl模块方法介绍,前提是要有root权限,否则只能自己下载perl模块自己解压安装了。 首次使用需要perl -MCPAN -e shell,以后只需要cpan即可 安装只有两个步骤,查询或者安装

    Windows 下安装Perl模块的方法讨论

    Windows 下安装Perl模块的方法讨论 手动编译方式 优点:通吃所有模块 缺点:有点麻烦 具体步骤:1安装编译器2设置编译器的环境变量3可能安装dmake 具体方法:如下 1.首先要有个c编译器2.编译步骤,在cpan上下载需要的...

    linux 离线安装perl-IPC-Cmd

    linux 离线安装perl-IPC-Cmd

    windows下安装perl模块方法和必备软件nmake dmake devcpp.zip

    windows下安装perl模块方法和必备软件nmake dmake devcpp: 方式一: 将 nmake.exe 放到system32目录下 用一下方式: perl Makefile.pl nmake nmake test nmake install 如果成功,将不用看下面内容。 方式二:...

    perl模块安装工具:cpanm

    cpanm是一种比cpan更简洁的perl模块安装工具。 cpanm本身其实只是一个可执行文件而已。将它下载到 bin 目录,然后添加执行权限就可以用了。 使用时,参数名直接为模块名称即可。如: $ sudo cpanm CGI::Session 可以...

    Linux/Unix下安装Perl模块的两种方法分享

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

    Module-Find:CPAN Perl模块的开发存储库Module :: Find

    Module-Find:CPAN Perl模块的开发存储库Module :: Find

    CPAN上处理xml的两个模块

    CPAN上处理xml文件的两个模块的说明,用于学习处理xml文件

    cpanf:从新镜像实时查询和安装 CPAN 模块

    名称App::CPAN::Fresh - 从新镜像实时查询和安装 CPAN 模块弃用由于 FriendFeed 已关闭,此模块不再工作。 您可以使用cpanm的--metacpan选项来启用 MetaCPAN API 搜索,这可以几乎实时地为您提供最近更新的模块。 ...

    Bugzilla安装步骤详解

    在windows环境下安装Bugzilla。需要在自己的机器上配置IIS。之后安装ActivePerl,MySQL以及Bugzilla。 安装过程中请保持网络畅通

    Linux下用Nginx作Perl程序服务器及其中Perl模块的配置

    性能方面也不亚于php,但是现在web程序php的流行程度perl无法比拟了,性能再好也枉然,但是部分小功能可以考虑使用perl的fastcgi来搞定.进入正题. 1. 准备软件环境: nginx:http://www.nginx.org perl:系统自带 ...

    Kafka:Kafka API(官方CPAN模块)的Perl实现

    Kafka:Kafka API(官方CPAN模块)的Perl实现

    perl-Astro-WaveBand:CPAN Perl Astro :: WaveBand模块,用于转换天文波段信息

    perl-Astro-WaveBand:CPAN Perl Astro :: WaveBand模块,用于转换天文波段信息

    strawberry-perl-5.28.0.1-64bit.msi

    Perl 在 Window 平台上有 ...ActiveState Perl和 Strawberry Perl最大的区别是 Strawberry Perl 里面有多包含一些 CPAN 里的模块, 所以Strawberry Perl 下载的安装文件有 80多M, 而ActiveState Perl 只有20M 左右。

    Perl 实例精解(第三版).pdf

    15.3.2 使用PPM在Windows系统上安装Perl模块 15.3.3 安装RDBMS 15.3.4 为MMS范例创建DSN 15.4 使用ADO和DBI访问MSS 15.4.1 Microsoft SQL Server--范例15-1和15-3的查询 15.4.2 范例15-1:ex1.p1在...

    PERL编程24学时教程.pdf

    14.2.3 用于通信的Perl模块 164 14.2.4 使用English模块 165 14.2.5 diagnostics模块 165 14.3 标准模块的完整列表 166 14.4 课时小结 167 14.5 课外作业 167 14.5.1 专家答疑 167 14.5.2 思考题 168 14.5.3 解答 ...

    perl-poe-smokebox-uploads-rsync:通过 rsync 获取上传的 CPAN 模块

    POE::Component::SmokeBox::Uploads::Rsync - 通过 rsync 获取上传的 CPAN 模块 版本 This document describes v1.001 of POE::Component::SmokeBox::Uploads::Rsync - released November 03, 2014 as part of POE-...

    Pinto:整理自己的Perl模块存储库

    Pinto是用于创建和管理Perl模块的类似于CPAN的自定义存储库的应用程序。 这样的存储库的目的是提供稳定的,经过整理的依赖关系堆栈,您可以使用标准的Perl工具链从该可靠的堆栈可靠地构建,测试和部署应用程序。 ...

    perl:其他个人Perl模块

    RRT Perl模块:copyright:2002–2018 Reuben Thomas 我在自己的代码中使用的其他Perl模块的集合。 也许有一天我会研究如何在CPAN上发布它们。 这些Perl模块是免费软件,已获得GNU GPL版本3(或您选择的任何更高版本)...

    coc-perl:coc.nvim的Perl语言服务器

    安装要求您需要安装perl模块Perl :: LanguageServer才能使此扩展正常工作,例如,在目标系统上运行“ cpan Perl :: LanguageServer”。 请确保始终始终运行最新版本的Perl :: LanguageServer。CocInstall 在(neo)...

Global site tag (gtag.js) - Google Analytics