Hi,

I'm trying to port a system to mod_perl. Basically, I've got a 'global.pl' script that I require() from my other scripts to load functionality such as cookies, DB connections, etc. This is an extract of my global.pl file:

#!/usr/bin/perl use DBI; use CGI; use Image::Size; sub env() { $query = $ENV{'QUERY_STRING'}; $cookie = $ENV{'HTTP_COOKIE'}; ($cookiename,$cookievalues) = split(/=/,$cookie); ($cookietype,$cookieuser) = split(/\&/,$cookievalues); $imgpath = "/home/e-smith/files/ibays/Primary/html/departments"; $imgpathweb = "/departments"; } sub form_read() { $q = new CGI; %fr = (); foreach ($q->param()) { $fr{$_} = $q->param($_); } } sub mysql_connect() { $dbh = DBI->connect("dbi:mysql:departments","user","passwd") or die "S +QL Connection Error."; }

So then, from my CGI scripts I can do the following:

#!/usr/bin/perl require '../global/global.pl'; &env(); &mysql_connect(); $sth = $dbh->prepare("select label,notes from departments where depart +ment='$query'"); $sth->execute; ($departmentlabel,$departmentnotes) = $sth->fetchrow_array; $sth->finish; $dbh->disconnect; &form_read(); print $fr{aformfield};

This all runs just fine as plain CGI, but starts crashing under Apache::Registry. Every a couple of reloads, I get an Internal Server Error, and in Apache's error log:

Undefined subroutine &Apache::ROOTdepartments::mod_2dperl::site::department_2epl::env ....

I tried searching the web for solutions, but the information I found is a little confusing.

Anyone knows what should be changed within the code above so that it runs correctly with Apache::Registry?

Any help is really appreciated.

Thanks,
Ralph


In reply to Porting to mod_perl issues by Anonymous Monk

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.