fenghzy 发表于 2017-5-17 09:23:36

Perl的library设置

  参考链接:


[*]http://stackoverflow.com/questions/841785/how-do-i-include-a-perl-module-thats-in-a-different-directory
[*]http://stackoverflow.com/questions/185114/how-do-i-use-a-perl-module-in-a-directory-not-in-inc
  在Fedora/RHEL/CentOS中,perl 的library默认安装路径为:
  @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .)
  如果要使用自定义的perllib,就需要参考以下的设置了。
  EDIT: Putting the right solution first, originally fromthis question. It's the only one that searches relative to themoduledirectory:

use FindBin;         # locate this script
use lib "$FindBin::Bin/.."; # use the parent directory
use yourlib;

  There's many other ways that search for libraries relative to thecurrentdirectory. You can invoke perl with the -I argument, passing the directory of the other module:

perl -I.. yourscript.pl

  You can include a line near the top of your perl script:

use lib '..';

  You can modify the environment variable PERL5LIB before you run thescript:

export PERL5LIB=$PERL5LIB:..

  The push(@INC) strategy can also work, but it has to be wrapped in BEGIN{} to make sure that the push is run before the module search:

BEGIN {push @INC, '..'}
use yourlib;
页: [1]
查看完整版本: Perl的library设置