转自:

http://www.cnblogs.com/itech/archive/2009/08/10/1542832.html

http://www.mike.org.cn/blog/index.php?load=read&id=643

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

安装方法

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

一 Linux/Unix下安装Perl模块有两种方法:手工安装和自动安装。

第一种方法是从CPAN上下载您需要的模块,手工编译、安装。第二种方法是使用CPAN模块自动完成下载、编译、安装的全过程。

A、手工安装的步骤:

  从 CPAN(http://search.cpan.org/)下载了Net-Server模块0.97版的压缩文件Net-Server-0.97.tar.gz,假设放在/usr/local/src/下。

  cd /usr/local/src

  解压缩这个文件,这时会新建一个Net-Server-0.97的目录。

  tar xvzf Net-Server-0.97.tar.gz

  换到解压后的目录:

  cd Net-Server-0.97

  生成 makefile:

  perl Makefile.PL

  生成模块:make

  测试模块(这步可有可无):

  make test
  
  如果测试结果报告“all test ok”,您就可以放心地安装编译好的模块了。

  安装模块前,先要确保您对 perl5 安装目录有可写权限(通常以 su 命令获得),执行:

  make install

  现在,试试 DBI 模块吧。如果下面的命令没有给出任何输出,那就没问题。

  $>perl -MNet::Server -e1

  上述步骤适合于 Linux/Unix下绝大多数的Perl模块。可能还有少数模块的安装方法略有差别,所以最好先看看安装目录里的 README 或 INSTALL。

有的时候如果是build.pl的需要以下安装步骤:(需要Module::Build模块支持)

perl Build.PL
 ./Build 
 ./Build test 
 ./Build install

B、使用CPAN模块自动安装方法一:

  安装前需要先联上网,并且您需要取得root权限。

  perl -MCPAN -e shell

  初次运行CPAN时需要做一些设置,如果您的机器是直接与因特网相联(拨号上网、专线,etc.),那么一路回车就行了,只需要在最后一步选一个离您最近的 CPAN 镜像站点。例如我选的是位于国内的http://www.cnblogs.com/itech/admin/ftp://www.perl87.cn/CPAN/ 。否则,如果您的机器位于防火墙之后,还需要设置ftp代理或http代理。下面是常用 cpan 命令。

  获得帮助
  cpan>help

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

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

  退出
  cpan>quit

C、使用CPAN模块自动安装方法二:

  cpan -i 模块名

  例如:cpan -i Net::Server

二 windows上perl模块安装 

A 手动(跟Linux类似) [解压后 perl makefile.pl nmake/dmake nmake/dmake install]

nmake需要cd C:\Program Files\Microsoft Visual Studio X\VC\bin and execute vcvars32.bat;然后执行nmake;

dmake 貌似是cpan环境配置好就有了在C:\Perl\site\bin下。

B Cpan (安装前需要对cpan配置,cpan需要安装其他的模块dmake和MinGw gcc compiler) (跟Linux类似)

C 如果使用ActivePerl,可以使用PPM(巧记Perl install PM module)来安装,使用PPM GUI或PPM Commandline。一般安装在site\lib下

PPM commandline实例如下:

a) add correct repositories..

c:\perl\bin\ppm repo add http://theoryx5.uwinnipeg.ca/ppms/package.lst

c:\perl\bin\ppm repo add http://www.roth.net/perl/packages/

b) add the packages

c:\perl\bin\ppm install Carp-Assert
c:\perl\bin\ppm install Log-Log4perl
c:\perl\bin\ppm install YAML-Syck

ppm install Path::Class

三 几个主要的CPAN站点有:

  国内:

  最新更新请查阅 http://cpan.org/SITES.html

  http://www.perl87.cn/CPAN/  网页镜像
  http://www.cnblogs.com/itech/admin/ftp://www.perl87.cn/CPAN/   模块镜像
  
  国外:http://www.cpan.org/

四 使用cpan和ppm安装时要注意模块名字的大小写

五 To get a list of the standard pragmatics(相当于c的宏定义) and modules, see perldoc perlmodlib.

我们可以直接输入 perldoc perlmodlib 来查看pragmaticsmodules

  Pragmatic Modules
They work somewhat like compiler directives (pragmata) in that they tend
to affect the compilation of your program, and thus will usually work well
only when used within a "use", or "no". Most of these are lexically
scoped, so an inner BLOCK may countermand them by saying: no integer;
no strict 'refs';
no warnings; which lasts until the end of that BLOCK. Some pragmas are lexically scoped--typically those that affect the $^H
hints variable. Others affect the current package instead, like "use vars"
and "use subs", which allow you to predeclare a variables or subroutines
within a particular file rather than just a block. Such declarations are
effective for the entire file for which they were declared. You cannot
rescind them with "no vars" or "no subs".
  Standard Modules
Standard, bundled modules are all expected to behave in a well-defined
manner with respect to namespace pollution because they use the Exporter
module. See their own documentation for details. To find out all modules installed on your system, including those without
documentation or outside the standard release, just use the following
command (under the default win32 shell, double quotes should be used
instead of single quotes). % perl -MFile::Find=find -MFile::Spec::Functions -Tlwe \
'find { wanted => sub { print canonpath $_ if /\.pm\z/ },
no_chdir => }, @INC'

(The -T is here to prevent '.' from being listed in @INC.) They should all
have their own documentation installed and accessible via your system
man() command. Note also that the command "perldoc perllocal" gives you a (possibly
incomplete) list of the modules that have been further installed on your
system. (The perllocal.pod file is updated by the standard MakeMaker
install process.)
  Extension Modules
Extension modules are written in C (or a mix of Perl and C). They are
usually dynamically loaded into Perl if and when you need them, but may
also be linked in statically. Supported extension modules include Socket,
Fcntl, and POSIX. Many popular C extension modules do not come bundled (at least, not
completely) due to their sizes, volatility, or simply lack of time for
adequate testing and configuration across the multitude of platforms on
which Perl was beta-tested. You are encouraged to look for them on CPAN
(described below), or using web search engines like Alta Vista or Google.

perl模块安装的更多相关文章

  1. Linux CPAN Perl 模块安装

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

  2. centos7 cpanm安装,及perl模块安装

    1. cpan安装 yum安装 yum install perl-App-cpanminus.noarch 注意:安装完成后,root及非root用户都可以使用cpanm安装模块,root用户直接用c ...

  3. Linux下perl模块安装

    perl模块下载地址: http://search.cpan.org/ 假设放在/usr/local/src/下 cd /usr/local/src 上传下载的压缩包CGI-Session-3.95. ...

  4. ---perl 模块安装方法

    http://blog.csdn.net/lincy100/article/details/7333794 $ perl -MCPAN -e shell install Log::Log4perlin ...

  5. perl 模块安装

    You can check if you have them installed in your machine with: > perl -e 1 -M<module> It wi ...

  6. perl模块安装——cpanm

    下载 wget  http://xrl.us/cpanm mv cpanm.1 cpanm 配置 在bashrc或zshrc里面加入下面的几句话 最好把相对路径改成绝度路径(将~换成你根目录的绝对路径 ...

  7. perl 简单学习,安装perl模块

    检查是否安装了某个perl模块 有多种方式 0.perldoc perlinstall 列出所有的模块及版本号 1. perl -M模块名 -e 1(模块名不加空格) 没有返回值则说明有此模块 2.p ...

  8. 非[无]root权限 服务器 下安装perl以及perl模块--转载

    转载自http://www.zilhua.com 在本博客中,所有的软件安装都在服务器上,且无root权限.理论上适合所有的用户. 我的安装目录 cd /home/zilhua/software 1. ...

  9. 非[无]root权限 服务器 下安装perl以及perl模块

    转载自http://www.zilhua.com 在本博客中,所有的软件安装都在服务器上,且无root权限.理论上适合所有的用户. 我的安装目录 cd /home/zilhua/software 1. ...

随机推荐

  1. Struts2第一天

    Struts2第一天 整体课程安排:3天知识点+2天练习 第一天:入门(action和result结果集)--一般的请求+响应 第二天:请求数据处理相关(参数接收.类型转换.合法性校验.国际化) 第三 ...

  2. ListView的条目点击焦点的问题

    由于ListView条目里有ImageButton,导致抢占了条目点击事件,所以在item的跟布局中加入 android:descendantFocusability="blocksDesc ...

  3. 百度用AR复现朝阳门,野心渐明直指AR平台

    近日,支付宝推出基于"AR+LBS"的AR实景红包后,BAT的另一个巨头百度也忍不住展示了自家AR技术.12月22日上午11点,百度邀请了一众媒体朋友前往朝阳门地铁站F口,体验期最 ...

  4. bashrc - PS1(提示符配色)

    PS1设置: liBlack="\[\033[0;30m\]"boBlack="\[\033[1;30m\]"liRed="\[\033[0;31m\ ...

  5. 编写高质量iOS代码的52个有效方法2-1

    一.变量的定义位置(用{}声明示例变量或者用@property属性声明实例变量) 1.用{}声明示例变量: 此方法生命的实例变量,编译器在编译时,会自动计算其偏移量(表示该变量距离存放对象的内存区域的 ...

  6. (转)eclipse自动补全的设置

    如果你用过Visual Studio的自动补全功能后,再来用eclipse的自动补全功能,相信大家会有些许失望. 但是eclipse其实是非常强大的,eclipse的自动补全没有VS那么好是因为ecl ...

  7. 4、Spring+MyBatis增删改查

    0.oracle数据库脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 cre ...

  8. stb_image读取图片数据

    #include <iostream> #include <fstream> #include <stbi/stb_image.h> const unsigned ...

  9. 使用rdesktop远程连接Windows桌面

    之前使用的是KDE下的krdc.该程序的Grab Keys功能存在bug,导致Alt+TAB大多数时候不能被捕捉,从而无法使用键盘切换窗口.不过,其全屏功能是正常的,在多显示器的情况下,全屏只在一个屏 ...

  10. LeetCode OJ 75. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...