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>";}

In reply to open and read file using cgi perl by vivek.vivek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.