But currently I am learning perl, a total beginner. I did my basic lessons and was trying to give myself a challenge with this program.
I think you've picked a rather challenging problem to solve in the general sense. This is the sort of thing that sounds easy when viewed from 30,000 feet, but from 50 feet, a lot of details emerge. Hey, those things that looked like ants are really people...etc...

I briefly perused the code presented by Hippo at Re: comparing any two text files and writing the difference to a third file. It appears to be well structured and well commented. A lot could be learned by intense study and experimentation with this code. I would add print statements to try to understand what each part is doing. There are some constructs that I would not expect a beginner to come up with, but study of this code would be instructive.

When faced with a complex problem, one idea is to simplify and solve a related, but less complex problem. One of the issues with file level diff is re-synchronization after a different block of lines is detected. How about just working with pairs of lines (and words within those lines) to start with?

  1. Bob went to the store.
  2. Bob and Mary went to the store.
Sentence (2) has "and Mary " as an addition.
If the sentences are swapped, then sentence (2) has "and Mary " as a deletion.
Work out some way to represent that.

What about a "substitution"?.
This might have to be represented as a deletion and an addition?

  1. Bob went to the store.
  2. Bob went to the movies.
Or perhaps:
  1. Bob went to the store and then to the bar for happy hour drinks.
  2. Bob and Mary went to the movies and then to the bar.
Anyway, the ideas is to work on a more constrained problem that illustrates at least some of the difficulties of the more general problem. My examples might not be the best, but I hope my idea is clear.

In reply to Re^3: comparing any two text files and writing the difference to a third file by Marshall
in thread comparing any two text files and writing the difference to a third file by balanunni

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.