Hi, I have 2 files as below
a.txt:
LOCK xxx yyy 123 1.1 fff
LOCK nnj hhh 789 2.2 uuu
b.txt:
LOCK xxx yyy 567 1.1 fff
LOCK nnj hhh 000 2.2 uuu
LOCK YUI hhh 520 2.3 ujk
I am comparing both files by browsing it through a webpage and parsing the file.
I need to compare the lines if only it starts with word LOCK and output the data.
The code is doing the comparison, but my problem is that the output is repeated with the count of number of lines in each file.
Eg: if a is compared with b, output repeted twice.
if b is compared with a, output is repeated 3 times.
my @files = ($file,$file1);
open(INOUT1,"<", $file1) or die "cant open output file ";
+
while ($linea = <INOUT1>){
open(INOUT,"<", $file) or die "cant open output file";
while ($line = <INOUT>){
chomp $linea;
next unless $linea =~ m/^LOCK /;
chomp $line;
next unless $line =~ m/^LOCK /;
foreach $file_n (@files){
$old = $files[0];
$new = $files[1];
if ($old eq $file_n){
@words=split(/\s+/,$line);
$feature1[$i]=$words[1];
$ver1[$i]=$words[3];
$exp1[$i]=$words[4];
$no1[$i]=$words[5];
$i++;
}
else{
@words=split(/\s+/,$linea);
$feature2[$ii]=$words[1];
$ver2[$ii]=$words[3];
$exp2[$ii]=$words[4];
$no2[$ii]=$words[5];
$ii++;
}
}
}close INOUT;
}close INOUT1;
print "<table border =1 align='left' style='font-family:Georgi
+a;'>
for ($b=0;$b<@feature1;$b++)
{ $test=0;
for($a=0;$a<@feature2;$a++)
{
if($feature1[$b] ne $feature2[$a])
{
$test++;
}
if($test == @feature2)
{
print "<tr><td>$feature1[$b]</td><td>$
+ver1[$b]</td><td>$exp1[$b]</td><td>$no1[$b]</td></tr>";
#$test++;
}
}
}
print "</table>";
print "<table border=1 align='left' style='font-family:Georgia
+;'>
for ($b=0;$b<@feature2;$b++)
{ $test=0;
for($a=0;$a<@feature1;$a++)
{
if($feature2[$b] ne $feature1[$a])
{
$test++;
}
if($test == @feature1)
{ #print $test;
print "<tr><td>$feature2[$b]</td><td>$ver2
+[$b]</td><td>$exp2[$b]</td><td>$no2[$b]</td></tr>";
}
}
}
print "</table>";}