[置顶] perl模块

1.怎么查看模块使用文档
  perldoc 模块名
  perldoc CGI

2.查看已经安装的所有模块
cpan -a

3.安装模块

perl Makefile.PL
make && make install

如果你没有权限安装可以指定安装目录
perl Makefiel.PL INSTALL_BASE=指定目录

or 

perl Build.PL
./Build && ./Build install

也可指定安装目录
perl Build.PL --install_base=指定目录

或在线安装模块
perl -MCPAN -e shell or perl -MCPAN -e "install MODULE NAME"



4.File::Basename模块

    Parse file paths into directory, filename and suffix
    #解析文件路径到目录、文件名和后缀
    这模块是跨平台的,那就在windows下演示使用方法
=pod 在Perl中,如果想将路径和文件名,文件后缀分别提取出来, 可以使用perl提供的模块File::Basename来实现。 如果你在windows下安装的是activeperl,那么这个模块已经安装了, 你就没必要再自己安装了,如果是使用linux系统,请到CPAN自己下载安装, 安装方法看我前面写的文章。下面我就具体来说一下这个模块的使用。 File::Basename中常用的方法有fileparse, basename, dirname。 fileparse方法会传回包含路经名称三个部份的串列; dirname方法传回路经位置; basename方法传回档案名称。 =cut
    使用方法:
    use File::Basename
    ($name,$path,$suffix) = fileparse($fullname,@suffixlist);
    $name = fileparse($fullname,@suffixlist);

    $basename = basename($fullname,@suffixlist);
    $dirname  = dirname($fullname);

 列子:
my $fullname = 'E:\perl_pack\seo.pl';
my @suffixlist = qw(.exe .pl .txt);
my ($name,$path,$suffix) = fileparse($fullname,@suffixlist);
print "name = $name\n";
print "path = $path\n";
print "suffix = $suffix\n";
$name = fileparse($fullname,@suffixlist);
print "name = $name\n";
my $Basename = basename($fullname,@suffixlist);
print "Basename = $Basename\n";
my $dirname = dirname($fullname);
print "dirname = $dirname\n"

5.File::Spec
  portably perform operations on file names
  可移植的执行操作的文件名

  用法:
  use File::Spec;
    $x=File::Spec->catfile('a', 'b', 'c');
    which returns 'a/b/c' under Unix. Or:
    use File::Spec::Functions;
    $x = catfile('a', 'b', 'c');

6.处理日期和时间的模块
NAME
    DateTime - A date and time object for Perl

VERSION
    version 1.21

SYNOPSIS
      use DateTime;

      $dt = DateTime->new(
          year => 1964,
          month => 10,
          day => 16,
          hour => 16,
          minute => 12,
          second => 47,
          nanosecond => 500000000,
          time_zone => 'Asia/Taipei',
      );

      $dt = DateTime->from_epoch( epoch => $epoch );
      $dt = DateTime->now; # same as ( epoch => time() )

      $year   = $dt->year;
      $month  = $dt->month;          # 1-12

      $day    = $dt->day;            # 1-31

      $dow    = $dt->day_of_week;    # 1-7 (Monday is 1)

      $hour   = $dt->hour;           # 0-23
      $minute = $dt->minute;         # 0-59

      $second = $dt->second;         # 0-61 (leap seconds!)

      $doy    = $dt->day_of_year;    # 1-366 (leap years)

      $doq    = $dt->day_of_quarter; # 1..

      $qtr    = $dt->quarter;        # 1-4

      # all of the start-at-1 methods above have corresponding start-at-0
      # methods, such as $dt->day_of_month_0, $dt->month_0 and so on

      $ymd    = $dt->ymd;           # 2002-12-06
      $ymd    = $dt->ymd('/');      # 2002/12/06

      $mdy    = $dt->mdy;           # 12-06-2002
      $mdy    = $dt->mdy('/');      # 12/06/2002

      $dmy    = $dt->dmy;           # 06-12-2002
      $dmy    = $dt->dmy('/');      # 06/12/2002

      $hms    = $dt->hms;           # 14:02:29
      $hms    = $dt->hms('!');      # 14!02!29

      $is_leap  = $dt->is_leap_year;

      # these are localizable, see Locales section
      $month_name  = $dt->month_name; # January, February, ...
      $month_abbr  = $dt->month_abbr; # Jan, Feb, ...
      $day_name    = $dt->day_name;   # Monday, Tuesday, ...
      $day_abbr    = $dt->day_abbr;   # Mon, Tue, ...

      # May not work for all possible datetime, see the docs on this
      # method for more details.
      $epoch_time  = $dt->epoch;

      $dt2 = $dt + $duration_object;

      $dt3 = $dt - $duration_object;

      $duration_object = $dt - $dt2;

      $dt->set( year => 1882 );

      $dt->set_time_zone( 'America/Chicago' );

      $dt->set_formatter( $formatter );

总结:1.主要讲了模块的安装方法,怎样查询已安装的某的方法及指定安装目录。
      2.简单介绍了File:Basename,File:Spec,DateTime模块的使用方法

你可能感兴趣的:(perl,文档,模块)