Link to home
Start Free TrialLog in
Avatar of Purdue_Pete
Purdue_Pete

asked on

Perl "Can't locate" problem

Hi,

I have a perl program (c.pm) which I am able to run from command line. However, I am not able to run it through web server.

Directory structure
project/a/b.pm
project/a/b/c.pm

In my c.pm, I am calling "use a::b"
Command line executes successfully.
But, the web server (error.log) reports"
Can't locate a/b.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/local/share/project/a/b/c.pm line 2.

DIRECTORY: /usr/local/share/project
Directory where c.pm is in @INC - I have both PERL5LIB setup in my bash profile to point to the DIRECTORY and in apache's virtual host
 PerlOptions +Parent
 PerlSwitches -I/<DIRECTORY>

perl -V shows the directory is in @INC
perl e "use c" does not print any error

Permission is 755 for the files.

NOTE: in error.log - @INC does not contain DIRECTORY - don't know why.

I am not sure what the problem is. Any suggestions are appreciated.

Thanks.
Avatar of Adam314
Adam314

Are you sure PERL5LIB is set when the scripts are run from within the webserver?  You could look at $ENV{PERL5LIB}.

You could add the directory to your perl script.  In your perl file (not the module .pm file, the perl file), add
    use lib '/usr/local/share/project';
Hope this helps,

Browser display:
A.pm: ========> A.pm
B.pm: =========> B.pm
C.pm: ===========> C.pm

directory as follow:
drwxr-xr-x    3 jccs0519     jccs0519         4096 May 11 13:21 A/
-rw-r--r--    1 jccs0519     jccs0519           86 May 11 13:18 A.pm
-rwxr-xr-x    1 jccs0519     jccs0519          295 May 11 13:22 test.cgi*

./A:
total 8
drwxr-xr-x    2 jccs0519     jccs0519         4096 May 11 13:22 B/
-rw-r--r--    1 jccs0519     jccs0519           72 May 11 13:21 B.pm

./A/B:
total 4
-rw-r--r--    1 jccs0519     jccs0519           76 May 11 13:22 C.pm

===========================================================
#!/usr/bin/perl

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use A;
use A::B;
use A::B::C;
$|=1;

print CGI->header();
print start_html("testing");
print qq[<li>A.pm: ];
A->say_apm();
print qq[<li>B.pm: ];
A::B->say_bpm();
print qq[<li>C.pm: ];
A::B::C->say_cpm();
print end_html;
================================
package A;

BEGIN {}

sub say_apm {
   print "========> A.pm\n";
}

return 1;

END {}
==========================
package A::B;

sub say_bpm {
   print "=========> B.pm\n";
}

return 1;
===========================
package A::B::C;

sub say_cpm {
  print "===========> C.pm\n";
}

return 1;
Avatar of Purdue_Pete

ASKER

Adam314,
adding use lib '/usr/local/share/project'; worked.

How do I print $ENV{PERL5LIB}? How is it different from echo $PERL5LIB?

echo $PERL5LIB prints '/usr/local/share/project' - so, I am not sure why @INC does not contain it. Any ideas?
The $PERL5LIB, if in a perl script is a scalar variable named PERL5LIB.  If in a shell script, it is an environment variable named PERL5LIB.

In a perl script, $ENV{PERL5LIB} is the environment variable named PERL5LIB.  

When you type "echo $PERL5LIB" from a command line, this is giving you the environment variable as defined by your current environment, which is different from the web server environment.  When you have a perl script print "$ENV{PERL5LIB}", this is displaying the value of the PERL5LIB environment variable in perl's environment, which is wherever it's being run (either the command line, or by the webserver).  My guess is the environment variable is not being setup in the web server environment.
Adam314,
Yes, you are right - I set PERL5LIB in my & root's bash profile. I am assuming I need to set in web server environment using SetEnv, right?
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial