eileen0 has asked for the wisdom of the Perl Monks concerning the following question:
I have a library of subroutines. I can use this library with .pl perl programs, by using a fully qualified require statement.
However, when I try to use the same library, with the same require statement, in a .cgi script, I get this error:
Can't locate /opt/webhost/ims/reports/efk/Lib1/HtmlLib.pl in @INC
I have tried adding a use statement. I get the same error, but now when it tells me what is in @INC, it does show the directory I need. I tried with both the directory, and the filename (with full path)#!/usr/bin/perl #------- use CGI::Carp qw(fatalsToBrowser); use lib "/opt/webhost/ims/reports/efk/Lib1"; #use lib "/opt/webhost/ims/reports/efk/Lib1/HtmlLib.pl"; require "/opt/webhost/ims/reports/efk/Lib1/HtmlLib.pl"; $htmlstr= "Content-type: text/html <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http:/ +/www.w3.org/TR/html4/loose.dtd'> <html> <head> <title>TEST HTML LIB</title> </head> <body> THIS IS A TEST :-); Have a nice Day. <br>"; $htmlstr .= "</body> </htm>"; print $htmlstr;
Software error: Can't locate /opt/webhost/ims/reports/efk/Lib1/HtmlLib.pl in @INC (@INC contains: /opt/webhost/ims/reports/efk/Lib1 /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
The code works if I remove the require, since I have not yet added any calls to the subroutines in the file I am requiring. First I want to get past this error.
The require file works in a non cgi perl program, using just the require statement (without a use statement). In the non cgi version of the code (run at the linux prompt), I am able to call the subroutines in the require file, without error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cgi, library of subroutines, use with require?
by aaron_baugher (Curate) on Oct 09, 2013 at 03:07 UTC | |
by eileen0 (Initiate) on Oct 09, 2013 at 03:15 UTC | |
by Anonymous Monk on Oct 09, 2013 at 06:47 UTC |