我在CGI程序中确实有以下HTML代码:

0  @@ process.html.ep
1  <% if ($errormsgs) { %>
2  <% for my $e (@$errormsgs){ %>
3  <%=$e%>
4  <br>
5  <% } %>
6  <a href="javascript:history.back();">Go back to fix the form</a><br>
7  <% } %>
8  <% if ($successmsg) { %>
9  <% for my $s (@$successmsg) { %>
10 <%=$s %>
11 <% } %>
12 <a href="<%= url_for('/') %>">Send another?</a><br>
13 <% } %>


所以当行1为true时,行12不打印,这就是我想要的,但是当行1为false时,则行6打印,但这不应该发生,因为我把它包围了用if语句括起来,所以我想要的是当$errormsgs为false时,则不应该显示<a href="javascript:history.back();">Go back to fix the form</a><br>

有任何想法吗?

最佳答案

$errormsgs最有可能是一个空的arrayref,其总值为true。尝试这个:

<% if (@$errormsgs) { %>

07-28 04:25