为什么我的Perl CGI程序不适用于Windows?

时间:2010-03-24 07:47:24

标签: perl xampp

我在index.pl C:\xampp\htdocs\perl文件夹中写了以下内容:

#!/usr/bin/perl
print "<html>";
print "<h2>PERL IT!</h2>";
print "this is some text that should get displyed in browser";
print "</html>";

当我浏览到http://localhost:88/perl/时,上面的HTML没有显示(我在IE FF和chrome中尝试过)。

原因是什么?

我在此Windows XP系统上安装了xamppapache2.2

3 个答案:

答案 0 :(得分:4)

另见How do I troubleshoot my Perl CGI Script?

您的问题是由于您的脚本没有发送相应的标题。

有效HTTP response由两部分组成:标题和正文。

您应该确保使用正确的CGI处理模块。 CGI.pm事实上的标准。但是,它有很多历史包袱,CGI::Simple提供了更清洁的选择。

使用其中一个模块,您的脚本将是:

#!/usr/bin/perl
use strict; use warnings;
use CGI::Simple;

my $cgi = CGI::Simple->new;

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>this is some text that should get displyed in browser</p>
</body>
</html>
HTML

请记住,print对多个参数没有任何问题。没有理由像1999年一样学习编程。

答案 1 :(得分:2)

也许是因为您没有将文字放在<body>标签之间。此外,您必须将内容类型指定为text/html

试试这个:

print "Content-type: text/html\n\n"; 
print "<html>";
print "<h2>PERL IT!</h2>";
print "<body>";
print "this is some text that should get displyed in browser";
print "</body>";
print "</html>";

另外,从链接rics给出,

Perl:
Executable: \xampp\htdocs and \xampp\cgi-bin
Allowed endings: .pl

所以你应该访问你的脚本,如: http://localhost/cgi-bin/index.pl

答案 2 :(得分:0)

我只是在猜测。

  • 您是否启动了apache服务器?
  • 88是否是到达apache的正确端口?

您也可以尝试http://localhost:88/perl/index.pl(因此将脚本名称添加到正确的地址)。

检查this documentation寻求帮助。