Solved

Perl "Can't locate" problem

Posted on 2009-05-10
6
418 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:Purdue_Pete
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24351591
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';
0
 
LVL 2

Expert Comment

by:jccs0519
ID: 24358767
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;
0
 

Author Comment

by:Purdue_Pete
ID: 24483957
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?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 39

Expert Comment

by:Adam314
ID: 24485060
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.
0
 

Author Comment

by:Purdue_Pete
ID: 24485104
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?
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 24485424
You can use SetEnv to specify the value in your apache config, and have apache set it for scripts it runs.  Or you could use PassEnv to have apache get the value from it's environment, and pass it to the scripts it runs.  Using SetEnv is probably easier.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now