Perl CGI:错误消息:脚本格式错误的标头.错误的标头=< body>:

我遇到了上述错误.

主要脚本如下

#!/opt/lampp/bin/perl
use lib "/opt/lampp/htdocs/PERL";
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use WEBPAGE::PageDesign;
use HTML::Form;

my $header = get_header() ;
my $html   = parse_form(\%ENV);

print "Content-type: text/html\n\n";
print <<HTML;
$header
$html
HTML

生成的html是正确的,但是带有html页面的脚本后面跟着错误

Error message:
<br />malformed header from script. Bad header=&lt;body&gt;: publish_scholarship.pl,

最佳答案 将打印标题行移至顶部.如果它仍然无法工作,则将其移至BEGIN块.

use warnings;
use strict;

BEGIN {
   print "Content-type: text/html\n\n";
}

use lib "/opt/lampp/htdocs/PERL";
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use WEBPAGE::PageDesign;
use HTML::Form;


my $header = get_header() ;
my $html   = parse_form(\%ENV);

print <<HTML;
$header
$html
HTML
点赞