Algorithm-Diff

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st

THANKS SECTION

Thanks to Ned Konz's for rewriting the module to greatly improve
performance, for maintaining it over the years, and for readilly handing
it over to me so I could plod along with my improvements.

(From Ned Konz's earlier versions):

Thanks to Mark-Jason Dominus for doing the original Perl version and
maintaining it over the last couple of years. Mark-Jason has been a huge
contributor to the Perl community and CPAN; it's because of people like
him that Perl has become a success.

Thanks to Mario Wolczko <mario@wolczko.com> for writing and making
publicly available his Smalltalk version of diff, which this Perl
version is heavily based on.

Thanks to Mike Schilli <m@perlmeister.com> for writing sdiff and
traverse_balanced and making them available for the Algorithm::Diff

lib/Algorithm/Diff.pm  view on Meta::CPAN

I think what they ended up using (and I hope someone will correct me,
because I am not very confident about this) was the `longest common
subsequence' method.  In the LCS problem, you have two sequences of
items:

    a b c d f g h j q z

    a b c d e f g i j k r x y z

and you want to find the longest sequence of items that is present in
both original sequences in the same order.  That is, you want to find
a new sequence I<S> which can be obtained from the first sequence by
deleting some items, and from the second sequence by deleting other
items.  You also want I<S> to be as long as possible.  In this case I<S>
is

    a b c d f g j z

From there it's only a small step to get diff-like output:

    e   h i   k   q r x y

lib/Algorithm/Diff.pm  view on Meta::CPAN

    $diff->Reset(1);    # Move to the first hunk
    $diff->Reset(-1);   # Move to the last hunk

C<Reset> returns the object, so, for example, you could use
C<< $diff->Reset()->Next(-1) >> to get the number of hunks.

=item C<Copy>

    $copy = $diff->Copy( $newPos, $newBase );

C<Copy> returns a copy of the object.  The copy and the original object
share most of their data, so making copies takes very little memory.
The copy maintains its own position (separate from the original), which
is the main purpose of copies.  It also maintains its own base.

By default, the copy's position starts out the same as the original
object's position.  But C<Copy> takes an optional first argument to set the
new position, so the following three snippets are equivalent:

    $copy = $diff->Copy($pos);

    $copy = $diff->Copy();
    $copy->Reset($pos);

    $copy = $diff->Copy()->Reset($pos);

C<Copy> takes an optional second argument to set the base for
the copy.  If you wish to change the base of the copy but leave
the position the same as in the original, here are two
equivalent ways:

    $copy = $diff->Copy();
    $copy->Base( 0 );

    $copy = $diff->Copy(undef,0);

Here are two equivalent way to get a "reset" copy:

    $copy = $diff->Copy(0);



( run in 0.241 second using v1.01-cache-2.11-cpan-1c8d708658b )