You haven't answered my questions.

The simple cases (just find if there is a difference or where the first difference is)can be dealt with something like this, which reads both files in parallel (assuming you have opened both files already):

while (my $line1 = <$FILE1>) { my $line2 = <$FILE2>; print "$line1 missing in file2\n" and last unless defined $line2; next if $line1 eq $line2; print "Difference found on line $.\n"; # you may want to exit here, depending on what you need }
It might be more complicated if you need to output more information.

You may also want to add some code at the end to figure out if $FILE2 has more lines than $FILE1 at the end. But you haven't said enough on your requirement for me to be willing to look at all the edge cases.

Please also note that there are some modules to do that, as you already know (judging from your original post).


In reply to Re^5: Getting error when trying to compare two files by Laurent_R
in thread Getting error when trying to compare two files by adalamre

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.