Hi monks, I have the following script to compare two text files.
#!/usr/bin/perl use strict; use warnings; my $f1 = $ARGV[0]; open FILE1, "$f1" or die "Could not open file \n"; my $f2= 'res1.txt'; open FILE2, "$f2" or die "Could not open file \n"; my $outfile = $ARGV[1]; my @outlines; my $n=0; my $n1=0; my $n2=0; foreach (<FILE1>) { my $y = 0; my $outer_text = $_; seek(FILE2,0,0); foreach (<FILE2>) { my $inner_text = $_; if($outer_text eq $inner_text) { $y = 1; print "$outer_text, Match found \n"; $n++; last; } } if($y != 1) { print "$outer_text,No Match Found \n"; push(@outlines, $outer_text); $n1++; } $n2++; } print "Total No.of queries:$n2\n"; print "No.of matched entries:$n\n"; print "No.of Mis-matched entries:$n1\n"; my $precision=$n/$n2; print "The precision is:$precision\n"; open (OUTFILE, ">Nonmatch") or die "Cannot open $outfile for writing \ +n"; print OUTFILE @outlines; close OUTFILE; close FILE1; close FILE2;

The script compares the two text file and gives the no.of matches and no.of mismatches. Also it writes mis-match into seperate file.

My doubt is when comparing the two file, if the 1st file has a sentence in line2(for e.g) and the 2nd file has empty space at line2, what happens is it takes that also has a mis-match. But what i want is, i want to differetiate the no.result(i.e empty space) from mis-match..

How can i do that.. Plz suggest me in this... Thanks..

In reply to on matching content of two text files by sarvan

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.