注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云之南

风声,雨声,读书声,声声入耳;家事,国事,天下事,事事关心

 
 
 

日志

 
 
关于我

专业背景:计算机科学 研究方向与兴趣: JavaEE-Web软件开发, 生物信息学, 数据挖掘与机器学习, 智能信息系统 目前工作: 基因组, 转录组, NGS高通量数据分析, 生物数据挖掘, 植物系统发育和比较进化基因组学

网易考拉推荐

perl5.12.4安装及检测与安装perl模块  

2012-01-18 21:06:47|  分类: perl&bioperl |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
tar zxvf perl-5.12.4.tar.gz
./Configure -des  -Dprefix=/home/zhaolei/software/perl-5.14.2
make
make install

检测PERL模块是否安装
#
查看所有的
perldoc perllocal
#
查看 Getopt::Long.pm是否安装
perl -MGetopt::Long -e "print\"module installed\n\""
module installed



如何安装perl模块


运行perl脚本时,经常会发现如下类似的错误:
forrest@forrest-desktop:~/study/perl/log4perl$ ./logToScreen.pl 
Can't locate Log/Log4perl.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at ./logToScreen.pl line 3.
BEGIN failed--compilation aborted at ./logToScreen.pl line 3.
这个是因为
use Log::Log4perl;
Log::Log4perl模块没有安装。

forrest@ubuntu:~/study/perl$ ./memcached.pl 
Can't locate Cache/Memcached.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at ./memcached.pl line 5.
BEGIN failed--compilation aborted at ./memcached.pl line 5.
这个是因为
use Cache::Memcached;
Cache::Memcached模块没有安装。

解决方法:
网上搜索了一下:发现有一篇文章写的非常好:Perl (Pete's notes) [http://www.cisl.ucar.edu/nets/intro/staff/siemsen/tools/perl.html#log4perl]
Installing Perl modules with CPAN.pm (best way)

Use the CPAN.pm module. To read about it, do "perldoc CPAN", or in XEmacs use the Perldoc pull-down when you're editing a Perl file.

The first time you use CPAN.pm, it will ask a long series of questions, the answers for which can be found below. Don't answer them until you've installed ncftp on the local machine.

If you've already installed CPAN and just want to use it, do like
(as root)
(sudo) perl -MCPAN -e shell
install Log::Log4perl
install HTML::TokeParser::Simple
h
q
    
The above will install Log4perl in /usr/lib/perl5/site_perl/5.6.1/Log/Log4perl.
需要注意的是必须使用root权限才能安装成功。


今天翻看了一下《Learn Perl, 5th》,第十一章是Perl Modules,一开始就是介绍怎么安装perl模块的。感觉总结的非常好。
1. Fining Modules:
Modules come in two types: those that come with Perl and that you should have available to you, and those that you can get from CPAN to install yourself. 

To find modules that don’t come with Perl, start at either CPAN Search (http://search.cpan.org) or Kobes’ Search (http://kobesearch.cpan.org/).* You can browse through the categories or search directly.

tips: 如何检查一个perl模块是否已经安装了?
可以使用perldoc moduleName检查。
不过首先要现安装perl-doc
$sudo apt-get install perl-doc
$ perldoc CGI
Try it with a module that does not exist and you’ll get an error message.
$ perldoc Llamas
$ No documentation found for "Llamas".

最佳实践:使用MCPAN的m moduleName命令
cpan[1]> m DBI
CPAN: Storable loaded ok (v2.20)
Going to read '/home/forrest/.cpan/Metadata'
  Database was generated on Wed, 21 Jul 2010 07:35:04 GMT
Module id = DBI
    DESCRIPTION  Generic Database Interface (see DBD modules)
    CPAN_USERID  TIMB (Tim Bunce <Tim.Bunce@pobox.com>)
    CPAN_VERSION 1.612
    CPAN_FILE    T/TI/TIMB/DBI-1.612.tar.gz
    UPLOAD_DATE  2010-07-16
    DSLIP_STATUS MmcOp (mature,mailing-list,C,object-oriented,Standard-Perl)
    MANPAGE      DBI - Database independent interface for Perl
    INST_FILE    /usr/local/lib/perl/5.10.1/DBI.pm
    INST_VERSION 1.612


cpan[2]> m DBD::Oracle
Module id = DBD::Oracle
    DESCRIPTION  Oracle Driver for DBI
    CPAN_USERID  DBIML (DBI Mailing Lists <dbi-users@perl.org>)
    CPAN_VERSION 1.24
    CPAN_FILE    P/PY/PYTHIAN/DBD-Oracle-1.24b.tar.gz
    DSLIP_STATUS MmcO? (mature,mailing-list,C,object-oriented,)
    INST_FILE    (not installed)

2. Installing Modules
三种方法:
法一:下载安装包手动安装
you can download the distribution, unpack it, and run a series of commands from the shell. Check for a README or INSTALL file that gives you more information. If the module uses MakeMaker,? the sequence will be something like this:
    $ perl Makefile.PL
    $ make install
If you can’t install modules in the system-wide directories, you can specify another directory with a PREFIX argument to Makefile.PL:
    $ perl Makefile.PL PREFIX=/Users/fred/lib
Some Perl module authors use another module, Module::Build, to build and install their creations. That sequence will be something like this:
    $ perl Build.PL
    $ ./Build install
缺点:无法自动安装依赖的包(Some modules depend on other modules though, and they won’t work unless you install yet more modules.)

法二:使用Perl自带的模块——CPAN.pm模块
$ perl -MCPAN -e shell
就是我们前面介绍的方法,这里就不赘述了。

法三:使用Perl自带的一个perl脚本——cpan脚本
$ cpan Module::CoreList LWP CGI::Prototype
  评论这张
 
阅读(6661)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016