当我测试我正在做的CGI表单的构建时,我得到了下面的错误。我正在尝试验证用户是否在CGI表单中输入了数据,以及值是否已提交。我是不是漏掉了什么?
致以敬意,
C:\xampp\cgi-bin>perl create_report.cgi
Can't modify logical and (&&) in scalar assignment at create_report.cgi line 105
, near "'Submitted')"代码:
if (defined $user_entry && $user_entry='Submitted') {
sub show_form {
print qq{<form name="input" action="create_report.cgi" method="post">\n};
print qq{<table align="center" border="1" bordercolor="black" cellpadding='2' cellspacing="0">\n};
print qq{<tr>};
print qq{<td align="right">Please enter the description of the Report you are copying</td};
print qq{</tr>\n};
print qq{<tr>};
print qq{<td align="left"><input type"text" width="7" name="spns" value=""};
print qq{<BR>Be sure to use just one or two words to find the report. Like "Mortgage Summary".</td>};
print qq{</table><center><input type="submit" value="Submitted"></center></form>\n};
}发布于 2012-04-23 23:47:44
这里有两个错误。首先,在需要字符串相等运算符(eq)的地方使用赋值运算符(=)。
但其次,你有一个关于优先级的问题。您希望将布尔条件解析为:
(defined $user) && ($entry = 'Submitted')但实际上,它被解析为:
defined ( ( $user && $entry ) = 'Submitted')我认为这清楚地说明了为什么你会得到你所看到的错误。
发布于 2012-04-23 23:30:19
如果要使用赋值运算符=检查Perl的值,请使用eq比较Perl中的两个字符串:
if (defined $user_entry && $user_entry eq 'Submitted')发布于 2012-04-23 23:30:28
您在这里混淆了=赋值和eq字符串等效运算符。使用eq (查看有关perlop中的Perl运算符的更多信息)。将子定义放在if中也不是一个好主意。
https://stackoverflow.com/questions/10283501
复制相似问题