嗨我很新的perl和我有一個問題,我的腳本的一部分被跳過的問題。Perl腳本跳過如果條件
我試圖驗證用戶。如果用戶輸入管理員和管理員,則顯示歡迎屏幕,否則顯示錯誤。
該腳本不斷跳過我的條件。有任何想法嗎?
#!/usr/bin/perl
use CGI;
use strict;
use warnings;
my $object = new CGI;
print "Content-type: text/html\n\n";
if ($object->param("submit")) {
validate_form();
} else {
display_form();
}
sub validate_form {
my $user = $object->param("user");
my $password = $object->param("password");
my $user2 = "admin";
my $password2 = "admin";
my $wrong = "WRONG";
if (my $user == my $user2 && $password == $password2) {
print $password;
} else {
print $wrong;
}
}
sub display_form {
print <<END_HTML;
<html>
<head>
<title>Assignment 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form method="post" action="/~int322_132sa13/cgi-bin/assn1/test2.pl" enctype="mu
User Name: <input type="text" name="user" />
Password:<input type="password" name="password" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
END_HTML
}
你真的'使用warnings'?你應該得到多個錯誤信息來解釋哪裏出了問題。他們說什麼? (提示:變量被重新聲明,undef值被比較,字符串值被比較爲數字)。哦,順便說一句,打印密碼看起來像是一個無知的想法,我希望這不會是「生產代碼」。 – amon
如果查看你的服務器日誌中的錯誤是太多工作,你總是可以使用CGI :: Carp qw(fatalsToBrowser);'',使用警告FATAL'也可以提供幫助。 – tjd
@amon我假設我應該使用eq而不是==。而這個純粹的測試環境。我得到的錯誤是「無法通過包」CGI「在test2.pl第6行找到對象方法」new「。」再次新的Perl不知道如何解決 – Anthony