I'm using Algorithm::Diff to keep track of proposed changes to documents. However if I have two proposed changes to the same document I want to be able to tell if the two changes overlap at all. If they don't I want to be able to merge the output of the results of the two different diffs into one set of changes.

As some sample code I have:

#!/usr/bin/perl use Algorithm::Diff qw(diff); use Data::Dumper; my $t1="This is the 1st lin\n This is the second line"; my $t2="This is the 1st line\n This is the second line`"; my $t3="This is the 1st lin\n This is the 2nd line`"; my @t1=split(//,$t1); my @t2=split(//,$t2); my @t3=split(//,$t3); @diff=diff(\@t1,\@t2); @diff2=diff(\@t1,\@t3); print Dumper(@diff); print "\n--------\n"; print Dumper(@diff2);
I get the following printed out for the differences between $t1 and $t2
$VAR1 = [ [ '+', 19, 'e' ] ]; $VAR2 = [ [ '+', 45, '`' ] ];
Here is the computed difference between $t1 and $t3
$VAR1 = [ [ '-', 33, 's' ], [ '-', 34, 'e' ], [ '-', 35, 'c' ], [ '-', 36, 'o' ], [ '+', 33, 2 ] ]; $VAR2 = [ [ '+', 41, '`' ] ];
How can I merge the two differences into one that can be applied to the original while verifying that the changes aren't conflicting. </CODE>

vroom | Tim Vroom | vroom@cs.hope.edu

In reply to Question about Algorithm::Diff by vroom

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.