You don't say what you're using the output of diff to do. But I would assume that since you're looking at its stdout rather than merely testing $? that you actually are using the diff output.

You may find my Algorithm::Diff module useful for this, though it is somewhat slower than the diff call. However, it may be easier than parsing diff output, depending on what you need to do, since it uses callbacks. Look at traverse_sequences().

On my system, it takes about 0.010 seconds of CPU time to diff two identical 2000-line files using the diff program, and 0.090 seconds of CPU time to diff the same two files using a Perl diff program that uses Algorithm::Diff. However, there is optimization for the common cases of identical lines at the beginning and ends of arrays. Changing the first and last lines results in 0.230 seconds of CPU time.

Anyway, you may want to give it a try.

update: got my decimal places right.


In reply to Re: `diff`ing two files (code) by bikeNomad
in thread `diff`ing two files (code) by deprecated

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.