Solved

Perl CGI issues "Undefined subroutine" error

Posted on 2004-09-03
4
758 Views
Last Modified: 2010-07-27
My Perl CGI sometimes prints out the expected HTML. Other times, it issues a "500 Internal Server Error". When this happens, the following message is printed to Apache's error.log:

[Fri Sep  3 19:20:00 2004] [error] Undefined subroutine &Apache::ROOT::about_2ecgi::myHeader called at /var/www/about.cgi line 4.\n

Below is the source code of the scipt (about.cgi). You may find a rendered version of it at http://metagloss.gotdns.com/about.cgi. (Or, you may receive an internal server error.)

-------------------about.cgi----------------------------
use common;


&myHeader;  #this is line 4

print <<EOF;
<br><br><br><center>
<font size=5 face="Verdana" size=5></font>
<br><br>Under Construction<br><br><br>
</center>
EOF

&myFooter;



-------------common.pm (called by about.cgi)--------------------------

use CGI qw(:standard escapeHTML);

return 1;


sub myHeader
{
print header();
print start_html("MetaGloss.org");

print <<EOF;
<body bgcolor="#eeeeee" marginwidth="0" marginheight="0" leftmargin="0"
        topmargin="0" text="#000000" link="000066" vlink="000066">
<center>
<table width=843px cellpadding=0 border=0>
<tr><td><img src="/images/metagloss5.jpg"></td></tr>
<tr><td><table cellpadding=0 border=0>
<tr><td width=80px bgcolor="#bbbbbb"><br /><br />
&nbsp;&nbsp;<a href=index.cgi>search</a><br /><br />
&nbsp;&nbsp;<a href=about.cgi>about</a><br /><br />
&nbsp;&nbsp;<a href=statistics.cgi>statistics</a><br /><br />
&nbsp;&nbsp;<a href=submit.cgi>submit</a><br /><br />
&nbsp;&nbsp;<a href=help.cgi>help</a><br /><br />
&nbsp;&nbsp;<a href=contact.cgi>contact</a>
</td><td width=763px bgcolor="#dddddd">
EOF
}



sub myFooter
{

print <<EOF;
<center><br /><br /><br />
<img src="/images/cat1.gif">
</center></td></tr></table></td></tr></table>
</center></body></html>
EOF
}


What part of my script could cause an "Undefined Subroutine" error to occasionally occur? (It does not always occur.)  I would very much appreciate any advice.
0
Comment
Question by:bobwood2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
inq123 earned 500 total points
ID: 11976650
Hi bobwood2000,

The reason why it's undefined is that the function's not exported.  You have to declare common.pm to be of Exporter type.  I'll give you a working example later.

Cheers!
0
 
LVL 8

Expert Comment

by:inq123
ID: 11976685
bobwood2000,

Add these lines immediately after use CGI... in your common.pm:

use vars qw(@ISA @EXPORT);
@ISA = ("Exporter");
@EXPORT = qw(myHeader myFooter);

I tested it and everything worked fine.
0
 

Author Comment

by:bobwood2000
ID: 11977829
Success! Thank you ing123!
0
 
LVL 8

Expert Comment

by:inq123
ID: 11978525
Thanks for the points!  I'll leave it up to mod about how to deal with more than 500 points then.  BTW, again, if you want the points for one question back you can ask in community service.

Best
inq
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

728 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