Text::Diff just uses Algorithm::Diff under the covers but returns the differences as text (usually written to STDOUT, I'd guess). Array::Diff is a subroutine of only about a dozen lines using Algorithm::Diff. So just use Algorithm::Diff.

Algorithm::Diff only works on arrays. It actually inserts each line of one of the files into a hash. So, if you've got a huge file, it needs a pretty big hash. The nature of the algorithm nearly requires things be done this way. But 10MB isn't so huge so I doubt you'll have a problem with running out of memory. Though, the number of lines per file might be large enough that the Perl implementation of the 'diff' algorithm (longest common subsequence) might be too slow for your purposes (I have it on my to-do list to make integration with the XS implementation of this algorithm, Algorithm::LCS, supported by Algorithm::Diff so that it uses it if you have it installed).

Your node also prompted me to look again at ways to reduce the amount of memory required by Algorithm::Diff. I think I see some fairly simple ways to dramatically reduce memory requirements so I'm breaking open the module to start working in a new release to make it support doing things much faster with less memory. Wish me luck. (:

- tye        


In reply to Re: Using diff in perl (Alg::Diff) by tye
in thread Using diff in perl by tsk1979

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.