[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

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.
0
Purdue_Pete
Asked:
Purdue_Pete
  • 3
  • 2
1 Solution
 
Adam314Commented:
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
 
jccs0519Commented:
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
 
Purdue_PeteAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Adam314Commented:
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
 
Purdue_PeteAuthor Commented:
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
 
Adam314Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now