Perl:use HTML::Entities错误

mzmfm0qo  于 10个月前  发布在  Perl
关注(0)|答案(3)|浏览(83)

我正在连接到一个运行HTML页面的服务器,代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1st February 2005), see www.w3.org">

  <title>Calculator</title>
  <link type="text/css" rel="stylesheet" href="mystyle.css">
</head>

<body>
  <h1>Calculator</h1>

  <p>This is a calculator form that uses a CGI script.</p>

  <form method="post" action="./cgi-bin/badcalc.pl">
    Expression <input type="text" name="exp" size="10"> 
    <input type="submit" value="Calculate">
    <input type="reset">
  </form><br>

  <p>The cgi script that does the calculation may be viewed <a href=
  "cgi-bin/code2html.pl?file=badcalc.pl">here</a>.</p>
</body>
</html>

字符串
这将链接到包含以下代码的Perl文件:

#!/usr/bin/perl

use strict;
use warnings;
use Safe; #using Sandbox
use CGI;
use HTML::Entities; #For encoding the output

my $query = new CGI;
my $exp = $query->param('exp');

print $query->header,
      $query->start_html(-title=>'Fixed calculator',
                    -style=>{'src' => '../mystyle.css'},
                -target=>'_blank'),
    $query->h1('Fixed calculator');

my $compartment = Safe->new();

##Defining a new sandbox
$compartment->permit_only(qw(atan2 sin cos exp log sqrt :default )); #Defines te functions that are permitted for execution
my $result = $compartment->reval($exp) or die("Error: ".$@);

#Execute the calculation, if input is trapped or an error occurs, die and print to log
if (defined $result)
{
    print "<br> ".encode_entities($exp)." = " encode_entities($result).""; ##Encodes the output to ensure that there is no problems on the page
}else
{
    print "<br> Oh dear! That input is not allowed or has been incorrectly formatted.\n"; #Makes error message suitable
}
print $query->end_html;


与旧版本(使用eval()而不是reval())相比,这应该可以执行简单的计算并提供更多的安全性,但是当我尝试执行像1+1这样的简单计算时,它会带回一个内部服务器错误,错误日志位于下面。

Can't locate HTML/Entities.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /home/1001542/public_html/cgi-bin/badcalc.pl line 10. BEGIN failed--compilation aborted at /home/1001542/public_html/cgi-bin/badcalc.pl line 10. [Mon May 06 10:58:05 2013] [error] [client 10.0.0.25] Premature end of script headers: badcalc.pl, referer: http://10.0.0.3/~1001542/calc.html


第10行是“使用HTML::Entities;“.
有什么帮助吗?

  • 编辑 * 原始Perl文件工作正常,奇怪的是。代码:
#!/usr/bin/perl

use strict;
use warnings;

use CGI;

my $query = new CGI;

my $exp = $query->param('exp');

print $query->header,
      $query->start_html(-title=>'Broken calculator',
                     -style=>{'src' => '../mystyle.css'},
                 -target=>'_blank'),
      $query->h1('Broken calculator');

my $result = eval($exp);
if (defined $result)
{
    print "<br> $exp = $result";
}else
{
    print "<br> oops! $@";
}

print $query->end_html;

  • 再次编辑 * 我使用大学提供的服务器来执行此操作,但现在已将其设置在我自己的虚拟机的Apache服务器上。如果我修好了,我会回到大家身边。
mlmc2os5

mlmc2os51#

我自己解决了。
由于我使用的是大学提供的服务器,因此无法安装所需的模块(HTML::Entities)。
我决定在虚拟机上的Apache Web服务器上设置所需的模块,并在整理了一些语法/拼写错误后设法让它以这种方式工作。
我安装 HTML::Entities 模块的方式是通过synaptic包管理器,只需搜索libhtml-parser-perl就可以找到并安装该模块。我重新启动了Apache和VM,以防万一。
感谢大家的投入!

yzuktlbb

yzuktlbb2#

CGI模块的escapeHTML做同样的事情。

gv8xihay

gv8xihay3#

通过安装libhtml-parser-perl包,我已经解决了同样的问题。使用以下代码安装软件包

sudo apt install libhtml-parser-perl

字符串
安装后,您可能必须重新启动webmin服务:

sudo service webmin restart

相关问题