Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

'Premature end of script headers' error

by newatperl (Acolyte)
on May 10, 2001 at 04:13 UTC ( [id://79301]=perlquestion: print w/replies, xml ) Need Help??

newatperl has asked for the wisdom of the Perl Monks concerning the following question:

I was working on a perl script that was working just fine except now it won't even compile because "Premature end of script headers" I've searched all over the script but I have yet to be able to find what this is referring too.. please help...
#!/util/bin/perl ###################################################################### +##### use CGI qw/:standard :html3 param/;; use CGI::Carp qw(fatalsToBrowser carpout); BEGIN{ print "Content-type: text/html\n\n"; open(STDERR, ">&STDOUT"); $| = 1; print ''; } ######################### #Beginning of Javascript ######################### #$JSCRIPT=<<JSEND; # if (navigator.appVersion.indexOf("PPC") != -1 || navigator.appVer +sion.indexOf("68K") != -1 || navigator.appVersion.indexOf("Mac")!= -1 +) # { # document.write("<LINK REL=\'STYLESHEET\' TYPE=\'text/css\' HR +EF=\'http://www.genome.wi.mit.edu/MPR/mprStyleMac.css\'>"); # } # else # { # document.write("<LINK REL=\'STYLESHEET\' TYPE=\'text/css\' HR +EF=\'http://www.genome.wi.mit.edu/MPR/mprStyle.css\'>"); # } # function moveover(txt) # { # window.status = txt; # } # #JSEND # #; #End of Javascript ###################################################################### +###### #NEW CGI OBJECT my $query = new CGI; #PRINT HEADER print $query->header; print $query->start_html( -title=>'Add to the Cancer Genomics Online Library'); # -script=>$JSCRIPT); #PRINT TITLE &print_title; #PRINT FORM print "<h2>Cancer Genomics Online Library Addition Form</h2>\n"; if ($query->param('Action') eq 'Submit') { # we have some data print "<h2>Entry Results</h2>\n"; # check data if (&check_entry($query) == 0) { &print_success($query); &make_entry($query); } else { print "<HR><H2>Errors Found</H2>\n"; print "<P>Please correct the errors above on the form below.\n +"; &print_form($query); } } else { &print_intro; &print_form($query); } &print_tail; print $query->end_html; #End of Program ###################################################################### +########### sub print_title { print "<table valign=top>\n"; print "<tr><td valign=top width=150><br>menubar will go here.</td> +\n"; print "<td valign=top align=left width=600><br>\n"; } sub print_intro { print"<p>Welcome to Cancer Genomics Online Library Addition Form.\ +n"; print"<p> Please fill in all relevant information.\n"; } sub print_form { my($query) = @_; my $width = 50; print $query->start_multipart_form; print "<h3><font color = red>Your Information</font></h3><p>"; print "<table>\n"; print "<tr><td><B>Your Name:</B></td><td>"; print $query->textfield( -name=>'yourname', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Your E-mail Address:</B></td><td>"; print $query->textfield( -name=>'youremail', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Your Daytime Phone:&nbsp&nbsp&nbsp</B></td><t +d>"; print $query->textfield( -name=>'yourphone', -size=>15); print "<td></tr>\n"; print"</table>\n"; print "<h3><font color = red>Entry Information</font></h3><p>"; print "<table>\n"; print "<tr><td><B>Publication Title:</B></td><td>"; print $query->textfield( -name=>'pubtitle', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Publication Author:</B></td><td>"; print $query->textfield( -name=>'pubauthor', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Date of Publication:</B></td><td>"; print $query->textfield( -name=>'pubdate', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Journal of Publication:</B></td><td>"; print $query->textfield( -name=>'pubjournal', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Online URL:</B></td><td>"; print $query->textfield( -name=>'puburl', -size=>$width); print "<td></tr>\n"; print "<tr><td><B>Category:</B></td><td>"; print $query->popup_menu( -name=>'pubcategory', -values=>['Choose a Category','Genetics','Mice','D +NA', 'None of the above'], -default=>'None', -labels=>\%labels); print "<td></tr>\n"; print "<tr><td><B>Relevant Keywords:</B></td><td>"; print $query->textfield(-name=>'pubkey1',-size=>(($width/4)-1) +); print "&nbsp&nbsp"; print $query->textfield(-name=>'pubkey2',-size=>(($width/4)-1) +); print "&nbsp&nbsp"; print $query->textfield(-name=>'pubkey3',-size=>(($width/4)-1) +); print "&nbsp&nbsp"; print $query->textfield(-name=>'pubkey4',-size=>(($width/4)-2) +); print "<td></tr>\n"; print "<tr><td><B>Additional Comments:</B></td><td>"; print $query->textarea( -name=>'pubcomments', -default=>'Add additional comments here.', -rows=>2, -columns=>($width-2)); print "<td></tr>\n"; print "<tr><td><B>Upload a copy: </B></td><td>"; print $query->filefield( -name=>'pubupload', -default=>'', -size=>($width-14), -maxlength=>100); print "<td></tr>\n"; print" </table>\n"; print $query->submit('Action','Submit'); print "&nbsp\n"; print $query->reset; print $query->endform; } sub subscribe_to_list { my($query) = @_; } sub print_success { print <<EOM; <p> Your addition to the Cancer Genomics Online Library has been succe +ssfully submitted. <p>Any Online Library Questions should go to &nbsp <a href="mailto:tamayo\@genome.wi.mit.edu"><tt>tamayo\@genome.wi.m +it.edu</tt></a>. <p>Any questions regarding the web site should go to &nbsp <a href="mailto:zhao\@mit.edu"><tt>zhao\@mit.edu</tt></a>. <p> <a href="http://waldo.wi.mit.edu/MPR/" target="_top">Back to Cance +r Genomics Home</a> EOM } sub check_entry { my($query) = @_; my($bad); $bad = 0; if ($query->param('yourname') !~ /\S+/) { $bad = 1; print "<p><b>Error</b>: Your Name field is blank\n"; } if ($query->param('youremail') !~ /\S+/) { $bad = 1; print "<p><b>Error</b>: E-mail field is blank\n"; } if ($query->param('youremail') !~ /\@/) { $bad = 1; print "<p><b>Error</b>: E-mail field doesn't have \@ sign.\n"; } if ($query->param('pubtitle') !~ /\S+/) { $bad = 1; print "<p><b>Error</b>: Publication Title field is blank.\ +n"; } if ($query->param('pubauthor') !~ /\S+/) { $bad = 1; print "<p><b>Error</b>: Publication Author field is blank. +\n"; } #if ($query->param('phone') !~ /\S+/) { # $bad = 1; # print "<p><b>Error</b>: Phone field is blank\n"; #} $bad; # return whether or not entry is good } sub make_entry { my($query) = @_; } sub print_tail { print <<END; </td></tr></table> <table> <tr><td valign=top align=left width=750> <hr> <font size=-2 face="ARIAL,GENEVA,HELVETICA,SANS-SERIF"> Dacheng Zhao <br> Last Edited: <script language="JavaScript"> <!-- hide script from old browsers lastmod = document.lastModified document.write(lastmod) // end hiding contents --> </script> <br>Contact the Webmaster at <i><a href="mailto:zhao\@mit.edu">zhao\@mit.edu</a></i> with q +uestions or comments </font> </td></tr></table> END }

Replies are listed 'Best First'.
Re: help!! another simple bug
by Anonymous Monk on May 10, 2001 at 14:05 UTC
    In general, to debug, you will find that

    1. Running from the command line is more useful than running via your browser and the webserver

    2. If the command line won't tell you what's wrong, the perl debugger will:perl -d yourscript.cgi (see the perldebug manpage for how it works).

    3. Sometimes, you do need to run via a browser (to get environment variables etc. right) and then CGI::Carp has a useful function called fatalsToBrowser:

    use CGI::Carp qw/fatalsToBrowser/;

    will show you runtime errors in your browser. (Not sure if it'll do the same for compilation errors tho.)

    Mmkay?

    dave

Re: help!! another simple bug
by Masem (Monsignor) on May 10, 2001 at 04:16 UTC
    The "premature end of headers" script generally implies that the script failed to compile due to a syntax error. You are lacking "-w" and "use strict;" which will help you locate any errors that the perl interpreter finds prior to running your program.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: help!! another simple bug
by Daddio (Chaplain) on May 10, 2001 at 04:24 UTC

    Well, when I tried running it from the command line, I got this error (with -w):

    a.cgi: Name "main::labels" used only once: possible typo at ./a.cgi li +ne 163.

    This came out before the Content-Type: text/html line. My guess is that you are trying to use \%labels and haven't defined the hash.

    Hope this helps...

    --
    D a d d i o

Re: help!! another simple bug
by perlmonkey (Hermit) on May 10, 2001 at 07:05 UTC
    The program works fine on my system. There are no warnings or errors that I see. If the code you posted here is the exact code you tested then I would assume that the code is not the problem.
    Make sure that "/util/bin/perl" exists and is executable by the webserver.
    Do you have other cgi scripts working on this webserver?
    Did you make the script executable (via chmod)?

    Good luck.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://79301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-03-28 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found