Solved

Perl "Can't locate" problem

Posted on 2009-05-10
6
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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