Solved

Perl "Can't locate" problem

Posted on 2009-05-10
6
413 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:Adam314
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

8 Experts available now in Live!

Get 1:1 Help Now