Catfish
Catfish

Reputation: 19314

Perl script runs in linux terminal, but errors in browser

I'm trying to run this simple script in the browser and it keeps erroring out. If I run it in linux, it runs fine.

Script - 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";
}

Error:

[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

Upvotes: 2

Views: 1399

Answers (3)

user2015339
user2015339

Reputation: 1

If you are a debian user :

$ sudo apt-get install libpath-class-perl

Upvotes: 0

ruakh
ruakh

Reputation: 183564

Where is the .pm file that defines Path::Class? (If you don't know, try adding BEGIN { print "@INC\n"; } right before line 8, and running the script from the command line.)

You need to add its parent directory to your @INC, using another use lib '...'; pragma.

Upvotes: 2

Platinum Azure
Platinum Azure

Reputation: 46233

When the script is run in the command line, @INC contains a path where Path/Class.pm might be found. This is apparently not true in the web browser case.

Make sure you get a good understanding of the script's working directory and @INC values when run as a web server, and figure out how to get the appropriate path (the parent of Path) into @INC if needed.

Start by dumping @INC in both cases and comparing them, to see what path might not be there.

Upvotes: 2

Related Questions