Solved

Perl CGI issues "Undefined subroutine" error

Posted on 2004-09-03
4
729 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
Comment Utility
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
Comment Utility
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
Comment Utility
Success! Thank you ing123!
0
 
LVL 8

Expert Comment

by:inq123
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

12 Experts available now in Live!

Get 1:1 Help Now