Perl脚本在linux终端中运行,但在浏览器中出错

时间:2011-11-29 15:03:42

标签: linux perl browser

我正在尝试在浏览器中运行这个简单的脚本,它会一直出错。如果我在linux中运行它,它运行正常。

脚本 - test.pl:

#!/home/biotools/perl/5.10.0/bin/perl
use lib '/home/biotools/current/lib/site_perl/5.10.0';
use lib '/people/users/123456/classPath/lib';
use IngresLXSetupNoLog;
use strict;
use warnings;

use Path::Class;  # this is line 8

my $dir = dir('./mydir'); # foo/bar

print "Content-type: text/html\n\n";

# Iterate over the content of foo/bar
while (my $file = $dir->next) {

    # See if it is a directory and skip
    next if $file->is_dir();

    # Print out the file name and path
    print $file->stringify . "\n";
}

错误:

[Tue Nov 29 08:46:29 2011] [error] Can't locate Path/Class.pm in @INC (@INC contains: /people/users/123456/classPath/lib /home/biotools/current/lib/site_perl/5.10.0/x86_64-linux /home/biotools/current/lib/site_perl/5.10.0 /usr/local/biotools/perl/5.10.0/lib/5.10.0/x86_64-linux /usr/local/biotools/perl/5.10.0/lib/5.10.0 /usr/local/biotools/perl/5.10.0/lib/site_perl/5.10.0/x86_64-linux /usr/local/biotools/perl/5.10.0/lib/site_perl/5.10.0 .) at /projects/apps/dev/cgi-bin/miscellaneous/studyinfo/test.pl line 8.
[Tue Nov 29 08:46:29 2011] [error] BEGIN failed--compilation aborted at /projects/apps/dev/cgi-bin/miscellaneous/studyinfo/test.pl line 8.
[Tue Nov 29 08:46:29 2011] [error] Premature end of script headers: test.pl

3 个答案:

答案 0 :(得分:2)

当在命令行中运行脚本时,@INC包含可能找到Path / Class.pm的路径。在网络浏览器案例中显然不是这样。

确保在作为Web服务器运行时很好地理解脚本的工作目录和@INC值,并弄清楚如何将适当的路径(Path的父路径)转换为@INC如果需要的话。

首先在两种情况下转储@INC并比较它们,看看哪条路径可能不存在。

答案 1 :(得分:2)

定义.pm的{​​{1}}文件在哪里? (如果您不知道,请尝试在第8行之前添加Path::Class,然后从命令行运行脚本。)

您需要使用其他BEGIN { print "@INC\n"; } pragma将其父目录添加到@INC

答案 2 :(得分:0)

如果您是debian用户:

$ sudo apt-get install libpath-class-perl