Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 为什么此密码检查未按预期工作?_Perl_Cgi - Fatal编程技术网

Perl 为什么此密码检查未按预期工作?

Perl 为什么此密码检查未按预期工作?,perl,cgi,Perl,Cgi,我正在尝试从php扩展。这是一个基本的问题,我已经无法解决它 password.pl #!/usr/bin/perl use CGI; $q = new CGI; print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print '<title>Card</title>'; print '</head>'; print '<body>

我正在尝试从php扩展。这是一个基本的问题,我已经无法解决它

password.pl

#!/usr/bin/perl

use CGI;
$q = new CGI;

print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Card</title>';
print '</head>';
print '<body>';
print '<FORM METHOD=POST ACTION=/card.pl>';
print '<INPUT TYPE=password NAME=password SIZE=25>';
print '<input type=submit value=Submit>';
print '</FORM>';
print '</body>';
print '</html>';

1;
password.pl表单中没有任何内容传递到card.pl?我以前用过一个模拟的例子,没有问题吗


更多咖啡…

严格使用
使用警告并查看错误日志。还有你的HTML

然后会提醒您注意以下问题:

在card.pl第7行使用“strict subs”时,不允许使用裸字“pass”

您可能想要:

($password eq 'pass')

在我继续努力消除CGI.pm滥用的过程中,您的第一个脚本会更好,因为——

use strict;
use warnings;
use CGI qw( :standard );

print
    header(),
    start_html("O HAI CARD"),
    start_form(-action => "card.pl"),
    fieldset(
             legend("None Shall Pass!"),
             password_field(-name => "password",
                            -size => 25),
             submit(-value => "Submit"),
             ),
    end_form(),
    end_html();
你的第二个,也许,举个例子,等等-

use strict;
use warnings;
use CGI;
my $q = CGI->new;

print
    $q->header,
    $q->start_html("O HAI CARD");

my $password = $q->param("password");

if ( $password eq "pass" )
{
  print $q->h2("You're all good");
}
else
{
  print $q->h2({-style => "color:#a00"},
           "You're all good");
}

print $q->end_html();
或者,也许更好,一起-

use strict;
use warnings;
no warnings "uninitialized";
use CGI qw( :standard );

print
    header(),
    start_html("O HAI CARD");

print param("password") eq "pass" ?
    h2("Yes!") : h2({-style => "color:#a00"}, ":(");

print 
    start_form(),
    fieldset(
             legend("None Shall Pass!"),
             password_field(-name => "password",
                            -size => 25),
             submit(-value => "Submit"),
             ),
    end_form(),
    end_html();

RIF,阅读文档:。

也许可以尝试一下
…ACTION=“/card.pl”
。此外,password.pl缺少headers部分。对于输出HTML,herdoc将更具可读性
use strict;
use warnings;
no warnings "uninitialized";
use CGI qw( :standard );

print
    header(),
    start_html("O HAI CARD");

print param("password") eq "pass" ?
    h2("Yes!") : h2({-style => "color:#a00"}, ":(");

print 
    start_form(),
    fieldset(
             legend("None Shall Pass!"),
             password_field(-name => "password",
                            -size => 25),
             submit(-value => "Submit"),
             ),
    end_form(),
    end_html();