我试图在浏览器中运行这个简单的脚本,并保持错误。 如果我在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
定义Path::Class
的.pm
文件在哪里? (如果您不知道,请尝试在第8行之前添加BEGIN { print "@INC\n"; }
,然后从命令行运行脚本。
你需要添加它的父目录到你的@INC
,使用另一个use lib '...';
附注。
当脚本在命令行中运行时, @INC
包含一个可能找到Path / Class.pm的路径。 这在网络浏览器的情况下显然是不正确的。
确保在作为Web服务器运行时,对脚本的工作目录和@INC
值有一个很好的理解,并根据需要弄清楚如何获得适当的路径(Path的父级)到@INC
。
在这两种情况下,开始倾销@INC
并比较它们,以查看可能不存在的路径。
如果你是一个debian用户:
$ sudo apt-get install libpath-class-perl