List::Compare
2つのファイルを比較し、出力をhtmlで出力するために使用していますが、配列を使用しているため、出力は異なる行ではなく1つの行で出力されます。
例
file1.txt
aaaa
bbbb
cccc
dddd
file2.txt
aaaa
bbbb
cccc
eeee
コード
use strict;
use warnings;
use Getopt::Long;
use List::Compare;
my $f1 = 'file1.txt';
open FILE1, "$f1" or die "Could not open file $f1 \n";
my $f2= 'file2.txt';
open FILE2, "$f2" or die "Could not open $f2 \n";
my $outputFile = 'finaloutput.txt';
my @body="";
push(@body, "<html> \n");
push(@body, "<head> \n");
push(@body, "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\" \n");
push(@body, " <TD>");
push(@body, "<div align=\"left\"><Table border=2 bordercolor= \"black\"> \n");
push(@body, "<tr bgcolor=\"ORANGE\"><TH><b>uniq in file1</b></TH><TH>uniq in file 2</TH><TH>common</TH></TR>");
push(@body, "<br>\n");
my @latest=<FILE1>;
my @pevious=<FILE2>;
my $compare = List::Compare->new(\@latest, \@pevious);
my @intersection = $compare->get_intersection;
my @firstonly = $compare->get_unique;
my @secondonly = $compare->get_complement;
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");
push(@body, "</div></Table>" );
my $Joining= join('', @body);
push(@body, "</body></font>");
push(@body, "</html>");
print FILE"$Joining";
close FILE;
close FILE1;
close FILE2;
これが私が最初の列のために得るhtml出力です:
<tr><td>aaaa
bbbb
cccc </td></tr>
私が欲しい:
<tr><td>aaaa</td> <td>bbbb</td><td>cccc</td></tr>
きちんと説明できたと思います。