Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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打印正确的html表_Html_Perl - Fatal编程技术网

使用perl打印正确的html表

使用perl打印正确的html表,html,perl,Html,Perl,我使用List::Compare比较两个文件并以html格式打印输出,但是由于我使用数组,因此输出是在一行中而不是在不同的行中 范例 file1.txt aaaa bbbb cccc dddd file2.txt aaaa bbbb cccc eeee 代码 使用严格; 使用警告; 使用Getopt::Long; 使用列表::比较; my$f1='file1.txt'; 打开文件1,“$f1”或“无法打开文件$f1\n”; my$f2='file2.txt'; 打开文件2,“$f2”或di

我使用
List::Compare
比较两个文件并以html格式打印输出,但是由于我使用数组,因此输出是在一行中而不是在不同的行中

范例

file1.txt
aaaa
bbbb
cccc
dddd 

file2.txt
aaaa
bbbb
cccc
eeee
代码

使用严格;
使用警告;
使用Getopt::Long;
使用列表::比较;
my$f1='file1.txt';
打开文件1,“$f1”或“无法打开文件$f1\n”;
my$f2='file2.txt';
打开文件2,“$f2”或die“无法打开$f2\n”;
my$outputFile='finaloutput.txt';
我的“身体”;
推送(@body,“\n”);
推送(@body,“\n”);
按(@body,更改此行:

push(@body, "<tr><td>@intersection</td>\n");
编辑

根据您的评论,如果我完全理解,请尝试以下方法:

把这个箱子换掉

print "Common in both:\n"."@intersection"."\n";
push(@body, "<tr><td>@intersection</td>\n");
print "uniq in first file:\n"."@firstonly"."\n";
push(@body, "<td>@firstonly</td>\n");
print "Items uniq in Second File:\n"."@secondonly"."\n";
push(@body, "<td>@secondonly</td></tr>\n");
print“两者通用:\n.“@crossion.”\n;
推送(@body,“@crossion\n”);
打印“第一个文件中的uniq:\n”。@firstonly”。\n;
推送(@body,“@firstonly\n”);
打印“第二个文件中的项目uniq:\n”。@secondonly”。\n;
推送(@body,“@secondonly\n”);
关于这一点:

my $nbrows = @intersection;
$nbrows = @firstonly if @firstonly > $nbrows;
$nbrows = @secondonly if @secondonly > $nbrows;
push @intersection, ("&nbsp;")x($nbrows - @intersection);
push @firstonly, ("&nbsp;")x($nbrows - @firstonly);
push @secondonly, ("&nbsp;")x($nbrows - @secondonly);
for my $i(0..$nbrows-1) {
    push @body, "<tr>";
    push @body, "<td>$firstonly[$i]</td>";
    push @body, "<td>$secondonly[$i]</td>";
    push @body, "<td>$intersection[$i]</td>";
    push @body, "<tr>\n";
}
my$nbrows=@crossion;
$nbrows=@firstonly如果@firstonly>$nbrows;
$nbrows=@secondonly如果@secondonly>$nbrows;
在交叉点处按(“”)x($nbrows-@交叉点);
按@firstonly,(“”)x($nbrows-@firstonly);
按@secondonly,(“”)x($nbrows-@secondonly);
对于我的$i(0..$nbrows-1){
推@body,“;
按@body,“$firstonly[$i]”;
按@body,“$secondonly[$i]”;
推动@body,“$intersection[$i]”;
按@body,“\n”;
}
此代码

  push(@body, "<tr><td>@intersection</td>\n");
push(@body,“@crossion\n”);
只需将数组的元素插入到由空格分隔的字符串中

你想要什么

  push(@body, "<tr>"); 
  push(@body, map {"<td>$_</td>"} @intersection);
  push(@body, "</tr>");
push(@body,”);
推送(@body,map{“$\}@intersection);
推动(@body,“”);

第一列是什么?
?首先,它看起来像是从
列表::Compare
方法(在
“@intersection”
行中插入)中获得未经比较的字符串,但是,最后一个元素后面没有换行符…嘿,谢谢你的回答,但它仍然是一行。它应该在三个不同的列中出现。“文件1中的uniq”的结果应该在该列下。文件2中的uniq的Reuslt“应该放在那个专栏下面,等等。嘿,非常感谢。这正是我想要的。这是一个很大的帮助。再次感谢:)
my @latest=<FILE1>;
chomp @latest;
my @pevious=<FILE2>;
chomp @pevious;
print "Common in both:\n"."@intersection"."\n";
push(@body, "<tr><td>@intersection</td>\n");
print "uniq in first file:\n"."@firstonly"."\n";
push(@body, "<td>@firstonly</td>\n");
print "Items uniq in Second File:\n"."@secondonly"."\n";
push(@body, "<td>@secondonly</td></tr>\n");
my $nbrows = @intersection;
$nbrows = @firstonly if @firstonly > $nbrows;
$nbrows = @secondonly if @secondonly > $nbrows;
push @intersection, ("&nbsp;")x($nbrows - @intersection);
push @firstonly, ("&nbsp;")x($nbrows - @firstonly);
push @secondonly, ("&nbsp;")x($nbrows - @secondonly);
for my $i(0..$nbrows-1) {
    push @body, "<tr>";
    push @body, "<td>$firstonly[$i]</td>";
    push @body, "<td>$secondonly[$i]</td>";
    push @body, "<td>$intersection[$i]</td>";
    push @body, "<tr>\n";
}
  push(@body, "<tr><td>@intersection</td>\n");
  push(@body, "<tr>"); 
  push(@body, map {"<td>$_</td>"} @intersection);
  push(@body, "</tr>");