如何编辑@INC条目以包含模块的新目录

Aho*_*tbi 2 linux apache perl cgi centos

我想知道如何在我的perl设置中添加一个新目录,以便搜索要包含的模块?

当我运行这一行时:

perl -w /var/www/cgi-bin/upload.cgi
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Can't locate config.pm in @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) at /var/www/cgi-bin/upload.cgi line 5.
BEGIN failed--compilation aborted at /var/www/cgi-bin/upload.cgi line 5.
Run Code Online (Sandbox Code Playgroud)

我搜索了Google,显然我应该将其/var/www/cgi-bin作为文件夹包含在内,以便Perl可以找到并包含它.

更多信息

以下是该计划的前几行:

use strict;
use lib '.';
use XFSConfig; #this was fixed by using -I command line switch
use XUpload; # this returns as an error!!!
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use LWP::UserAgent;
Run Code Online (Sandbox Code Playgroud)

mob*_*mob 5

有几种方法,其中许多方法涉及perlfaq8:如何在运行时将目录添加到包含路径?

1)使用-I命令行开关

perl -w -I/var/www/cgi-bin /var/www/cgi-bin/upload.cgi
Run Code Online (Sandbox Code Playgroud)

2)使用PERLLIBPERL5LIB环境变量

export PERLLIB="$PERLLIB:/var/www/cgi-bin"
perl -w /var/www/cgi-bin/upload.cgi

PERL5LIB="$PERL5LIB:/var/www/cgi-bin" perl -w /var/www/cgi-bin/upload.cgi
Run Code Online (Sandbox Code Playgroud)

3)lib在代码中使用pragma

# somewhere near the top of  /var/www/cgi-bin/upload.cgi
use strict;
use warnings;
use lib '/var/www/cgi-bin';
Run Code Online (Sandbox Code Playgroud)

  • 如果您有CGI程序,请使用#2,并且可以使用类似.htaccess的内容.否则,使用#3 (3认同)