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.


In reply to cgi, library of subroutines, use with require? by eileen0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.