Solved

Perl CGI issues "Undefined subroutine" error

Posted on 2004-09-03
4
733 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now