Solved

Perl CGI issues "Undefined subroutine" error

Posted on 2004-09-03
4
739 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
  • 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

821 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