Perl 如何在CGI程序中更改rowspan属性?
我正在编写一个CGI脚本来处理表单数据,它应该在表中打印输入的名称及其值。当我有一个或多个同名值时,该名称应跨行,以容纳与该名称对应的所有值。例如,如果我有一个名称“color”,它的值为“red”、“green”、“blue”,那么颜色应该跨越表中的3行。我的问题是,如何更改脚本中的rowspan属性以适应以下情况:Perl 如何在CGI程序中更改rowspan属性?,perl,cgi,Perl,Cgi,我正在编写一个CGI脚本来处理表单数据,它应该在表中打印输入的名称及其值。当我有一个或多个同名值时,该名称应跨行,以容纳与该名称对应的所有值。例如,如果我有一个名称“color”,它的值为“red”、“green”、“blue”,那么颜色应该跨越表中的3行。我的问题是,如何更改脚本中的rowspan属性以适应以下情况: #!/usr/bin/perl -- use strict; use CGI; print <<HTTP; Status: 200 OK Content-Type:
#!/usr/bin/perl --
use strict;
use CGI;
print <<HTTP;
Status: 200 OK
Content-Type: text/html
HTTP
print <<HTML;
<html>
<head>
<title>Parameters<title>
<head>
<body>
<table border="1" cellpadding="5" cellspacing="1">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
HTML
my $query = new CGI;
my($name, $value);
foreach $name ( $query->param)
{
print "<tr>";
print "<td>$name</td>";
foreach $value($query->param($name))
{
print "<td>$value</td>";
print "</tr>";
}
}
#/usr/bin/perl--
严格使用;
使用CGI;
打印参数($name))
{
打印“$value”;
打印“”;
}
}
试试这个:
my $query = new CGI;
my($name, $value);
foreach $name ($query->param) {
my @values = $query->param($name);
my $count = @values;
print "<tr>";
print "<td rowspan='$count'>$name</td>";
print "<td>".shift(@values)."</td>";
print "</tr>";
foreach $value (@values) {
print "<tr>";
print "<td>$value</td>";
print "</tr>";
}
}
my$query=新CGI;
我的($name,$value);
foreach$name($query->param){
my@values=$query->param($name);
我的$count=@值;
打印“”;
打印“$name”;
打印“.shift(@values)”;
打印“”;
foreach$value(@values){
打印“”;
打印“$value”;
打印“”;
}
}
BTW,我建议您考虑使用一些模板处理系统,例如
< P>试试这个:my $query = new CGI;
my($name, $value);
foreach $name ($query->param) {
my @values = $query->param($name);
my $count = @values;
print "<tr>";
print "<td rowspan='$count'>$name</td>";
print "<td>".shift(@values)."</td>";
print "</tr>";
foreach $value (@values) {
print "<tr>";
print "<td>$value</td>";
print "</tr>";
}
}
my$query=新CGI;
我的($name,$value);
foreach$name($query->param){
my@values=$query->param($name);
我的$count=@值;
打印“”;
打印“$name”;
打印“.shift(@values)”;
打印“”;
foreach$value(@values){
打印“”;
打印“$value”;
打印“”;
}
}
BTW,我建议您考虑使用一些模板处理系统,例如:< /p>在最小适用范围内声明变量。很少和延迟打印。在最小的适用范围内声明变量。印刷很少,而且很晚。