Apache XAMPP服务器上的Perl提供了erorr 500
我对perl非常陌生,我正在尝试设置一个运行perl的web服务器 我确实使用了另一个脚本,但使用这个脚本时,我出现了以下错误: 服务器错误 服务器遇到内部错误,无法完成 你的要求 错误消息:在headers:index.pl之前结束脚本输出 如果您认为这是服务器错误,请联系网站管理员 误差500 本地主机Apache/2.4.9(Win32)OpenSSL/1.0.1g PHP/5.5.11 这是我的剧本:Apache XAMPP服务器上的Perl提供了erorr 500,apache,perl,xampp,Apache,Perl,Xampp,我对perl非常陌生,我正在尝试设置一个运行perl的web服务器 我确实使用了另一个脚本,但使用这个脚本时,我出现了以下错误: 服务器错误 服务器遇到内部错误,无法完成 你的要求 错误消息:在headers:index.pl之前结束脚本输出 如果您认为这是服务器错误,请联系网站管理员 误差500 本地主机Apache/2.4.9(Win32)OpenSSL/1.0.1g PHP/5.5.11 这是我的剧本: #!"C:\xampp\perl\bin\perl.exe" use strict;
#!"C:\xampp\perl\bin\perl.exe"
use strict;
use warnings;
#Open file and define $pcontent as content of body.txt
open(FILE,"body.txt");
local $/;
my $pcontent = <FILE>;
close(FILE)
#Open file and define $ptitle as content of title.txt
open(FILE,"title.txt");
local $/;
my $ptitle = <FILE>;
close(FILE)
#open html code
print "Content-type: text/html\n\n";
print "<html>";
#set html page title
print "<head>";
print "<title>$ptitle</title>";
print "</head>";
print "<body>";
#set the <body> of the html page
if ($pcontent = ""){
print "
<H1>ERROR OCCURED!</h1>"
} else{
print $pcontent;
};
#close the html code
print "</body>";
print "</html>";
#!“C:\xampp\perl\bin\perl.exe”
严格使用;
使用警告;
#打开文件并将$pcontent定义为body.txt的内容
打开(文件“body.txt”);
本地$/;
我的$pcontent=;
关闭(文件)
#打开文件并将$ptitle定义为title.txt的内容
打开(文件“title.txt”);
本地$/;
我的$ptitle=;
关闭(文件)
#打开html代码
打印“内容类型:text/html\n\n”;
打印“”;
#设置html页面标题
打印“”;
打印“$ptitle”;
打印“”;
打印“”;
#设置html页面的
如果($pcontent=“”){
“打印”
发生错误!”
}否则{
打印$pcontent;
};
#关闭html代码
打印“”;
打印“”;
它不起作用的原因是Perl代码存在语法错误,导致无法编译。您可以通过运行
perl -c yourscript.pl
如果我们这样做,我们会发现:
syntax error at yourscript.pl line 11, near ")
如果我们看第11行,我们会发现前面的那行语句末尾缺少一个分号
close(FILE) # <--- need semicolon here.
当然都是好建议。但是,你认为推荐而不是建议初学者包括手动
或die
语句怎么样?在我看来,懒惰无处不在,因此autodie不仅自动处理错误消息,它还包含比不可避免的或die$更多的信息我们经常看到的代码>。autodie
也是一个不错的选择。不过,在给人们提供捷径之前,我喜欢确保他们了解发生了什么
use strict;
use warnings;
#Open file and define $pcontent as content of body.txt
my $pcontent = do {
open my $fh, '<', 'body.txt' or die "Can not open body.txt: $!";
local $/;
<$fh>;
};
#Open file and define $ptitle as content of title.txt
my $ptitle = do {
open my $fh, '<', 'title.txt' or die "Can not open title.txt: $!";
local $/;
<$fh>;
};
#open html code
print "Content-type: text/html\n\n";
print "<html>";
#set html page title
print "<head>";
print "<title>$ptitle</title>";
print "</head>";
print "<body>";
#set the <body> of the html page
if ($pcontent eq ""){
print "<H1>ERROR OCCURED!</h1>"
} else{
print $pcontent;
};
#close the html code
print "</body>";
print "</html>";