Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
CGI Error Posted by Raza on 29 Oct 2004 at 1:40 AM
Hi !

I am a Perl newbie. I recently added the IIS 5.1 component to my computer running Win XP and configured it to run CGI programs.I use SiePerl.
I save my programs in k:\inetpub\wwwroot\cgi-bin.I can now successfully run programs from the browser using http://localhost/cgi-bin/<program name>.pl
But using using subroutines in my cgi programs is giving me a tough time.e.g.) When I run the following hello.pl from the browser using http://localhost/cgi-bin/hello.pl it gives me the following error :

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
htmlhead.pl did not return a true value at k:\inetpub\wwwroot\cgi-bin\hello.pl line 1.


The following is the code for hello.pl.

require "htmlhead.pl";
require "htmlend.pl";

&html_header("What a wonderful day...");
print "<h1> Hello World\n";
&html_footer;


Code for htmlhead.pl

sub html_header
{
	
	print "Content-type:text/html\n\n";

	print "<html>\n";

	print "<head>\n";

	print "<title>";

	print "@_";

	print "</title>\n</head>\n";

	print "<body>\n";
}


And finally, the code for htmlend.pl

sub html_footer
{
		
	print "\n</body>\n";

	print "</html>";

}



Plz help...
Thank you
Report
Re: CGI Error Posted by Weirdofreak on 29 Oct 2004 at 3:40 AM
From the error message, I'd guess that htmlhead.pl is returning false, so it doesn't get past the first require. To solve it, end the file with "1;" so that it returns true, or use do, which I don't think cares what the return value of the file is, instead of require. Also, you may want to put the subroutine declarations in the same file so you don't need to do two do/requires.

It might also not be finding htmlhead.pl and htmlend.pl - check @INC to make sure it's looking in the right place, or the CWD if they should be found in (dot). The CWD can be obtained with
use CWD;
$cwd = getcwd();


Oh, and you might want to add a character encoding and doctype, and close that H1...



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.