Perl環境的檢查和配置

檢查Perl環境已安裝了哪些包的方法。html

方法一:web

運行命令 perldoc perllocal即列出全部包的詳細信息。sql

[root@subv2 ~]# perldoc perllocal
PERLLOCAL(1)          User Contributed Perl Documentation         PERLLOCAL(1)

       Mon Sep 28 19:46:52 2009: "Module" AppConfig

       ·   "installed into: /usr/lib/perl5/site_perl/5.8.8"

       ·   "LINKTYPE: dynamic"

       ·   "VERSION: 1.66"

       ·   "EXE_FILES: "

       Mon Sep 28 19:47:13 2009: "Module" Template

       ·   "installed into: /usr/lib/perl5/site_perl/5.8.8"

       ·   "LINKTYPE: dynamic"

       ·   "VERSION: 2.22"

       ·   "EXE_FILES: bin/tpage bin/ttree"

       Mon Sep 28 19:47:24 2009: "Module" Email::MIME::Encodings

       ·   "installed into: /usr/lib/perl5/site_perl/5.8.8"

       ·   "LINKTYPE: dynamic"
......

方法二:shell

運行perl腳本:bash

#!/usr/bin/perl
use strict;
use ExtUtils::Installed;

my $inst= ExtUtils::Installed->new();

my @modules = $inst->modules();

foreach(@modules)
{
  my $ver = $inst->version($_) || "???";
  printf("%-12s --  %s\n", $_, $ver);   
}

檢查包的路徑 perldoc -l <package name>app

[root@subv2 ~]# perldoc -l CGI
/usr/lib/perl5/5.8.8/CGI.pm
[root@subv2 ~]#

查看每一個包的詳情perl doc <package name>
less

[root@subv2 ~]# perldoc -l CGI
/usr/lib/perl5/5.8.8/CGI.pm
[root@subv2 ~]# perldoc CGI
CGI(3)                User Contributed Perl Documentation               CGI(3)

NAME
       CGI - Simple Common Gateway Interface Class

SYNOPSIS
         # CGI script that creates a fill-out form
         # and echoes back its values.

         use CGI qw/:standard/;
         print header,
               start_html(’A Simple Example’),
               h1(’A Simple Example’),
               start_form,
               "What’s your name? ",textfield(’name’),p,
               "What’s the combination?", p,
               checkbox_group(-name=>’words’,
                              -values=>[’eenie’,’meenie’,’minie’,’moe’],
                              -defaults=>[’eenie’,’minie’]), p,
               "What’s your favorite color? ",

另外,
ide

Perl環境有一些經常使用配置。ui

Perl的配置主要就是cpan,對於CPAN的配置,都存放在~/.cpan這個目錄中。能夠刪除這個目錄而後運行cpan來從新配置。this

[root@subv2 .cpan]# cpan

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support enabled

                                                                                                    cpan> help

Display Information
 command  argument          description
 a,b,d,m  WORD or /REGEXP/  about authors, bundles, distributions, modules
 i        WORD or /REGEXP/  about anything of above
 r        NONE              reinstall recommendations
 ls       AUTHOR            about files in the author's directory

Download, Test, Make, Install...
 get                        download
 make                       make (implies get)
 test      MODULES,         make test (implies make)
 install   DISTS, BUNDLES   make install (implies test)
 clean                      make clean
 look                       open subshell in these dists' directories
 readme                     display these dists' README files

Other
 h,?           display this menu       ! perl-code   eval a perl command
 o conf [opt]  set and query options   q             quit the cpan shell
 reload cpan   load CPAN.pm again      reload index  load newer indices
 autobundle    Snapshot                force cmd     unconditionally do cmd
                                                                                                    cpan> o conf
CPAN::Config options from /usr/lib/perl5/5.8.8/CPAN/Config.pm:
    commit             Commit changes to disk
    defaults           Reload defaults from disk
    init               Interactive setting of all options

    applypatch         
    auto_commit        0
    build_cache        10
    build_dir          /root/.cpan/build
    build_dir_reuse    0
    build_requires_install_policy yes
    bzip2              /usr/bin/bzip2
    cache_metadata     1
    check_sigs         0
    colorize_output    0
    commandnumber_in_prompt 1
    connect_to_internet_ok 1
    cpan_home          /root/.cpan
    dontload_hash     
    ftp                /usr/kerberos/bin/ftp
    ftp_passive        1
    ftp_proxy          
    getcwd             cwd
    gpg                /usr/bin/gpg
    gzip               /bin/gzip
    halt_on_failure    0
    histfile           /root/.cpan/histfile
    histsize           100
    http_proxy         http://10.99.60.201:8080
    inactivity_timeout 0
    index_expire       1
    inhibit_startup_message 0
    keep_source_where  /root/.cpan/sources
    load_module_verbosity none
    make               /usr/bin/make
    make_arg           
    make_install_arg   
    make_install_make_command /usr/bin/make
    makepl_arg         
    mbuild_arg         
    mbuild_install_arg 
    mbuild_install_build_command ./Build
    mbuildpl_arg       
    ncftp              
    ncftpget           
    no_proxy           
    pager              /usr/bin/less
    patch              /usr/bin/patch
    perl5lib_verbosity none
    prefer_external_tar 1
    prefer_installer   MB
    prefs_dir          /root/.cpan/prefs
    prerequisites_policy ask
    proxy_pass         1qaz@WSX
    proxy_user         wangyzj
    scan_cache         atstart
    shell              /bin/bash
    show_unparsable_versions 0
    show_upload_date   0
    show_zero_versions 0
    tar                /bin/tar
    tar_verbosity      none
    term_is_latin      1
    term_ornaments     1
    test_report        0
    trust_test_report_history 0
    unzip              /usr/bin/unzip
    urllist           
        http://mirrors.sohu.com/CPAN/
    use_sqlite         0
    version_timeout    15
    wget               /usr/bin/wget
    yaml_load_code     0
    yaml_module        YAML


                                                                                                    cpan> 
                                                                                                    cpan> o conf http_proxy ""
    http_proxy         

                                                                                                    cpan> o conf proxy_pass ""
    proxy_pass         

                                                                                                    cpan> o conf proxy_user ""
    proxy_user         

             
cpan> o conf commit
commit: wrote /usr/lib/perl5/5.8.8/CPAN/Config.pm

對於web的cgi程序,能夠使用下面的腳原本檢查:

#!C:/strawberry/perl/bin/perl.exe
##
##  printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}
print "\n\@INC = \n";
print join("\n",@INC);

在Apache的配置中,能夠配置增長perl的環境變量。

<Directory "/opt/bugzilla-4.4.11">

    AddHandler cgi-script .cgi

    Options Indexes ExecCGI FollowSymLinks

    SetEnv PERL5LIB /opt/bugzilla-4.4.11:/opt/bugzilla-4.4.11/lib:.

    DirectoryIndex index.cgi

    AllowOverride None

    Order allow,deny

    Allow from all

</Directory>

相關文章
相關標籤/搜索