133 lines
3.1 KiB
HTML
133 lines
3.1 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Algorithm::DiffOld</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Algorithm::DiffOld</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2018-08-25<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Algorithm::DiffOld - Compute `intelligent' differences between two files / lists
|
|
but use the old (<=0.59) interface.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>NOTE</H2>
|
|
|
|
|
|
|
|
This has been provided as part of the Algorithm::Diff package by Ned Konz.
|
|
This particular module is <B></B><FONT SIZE="-1"><B>ONLY</B></FONT><B></B> for people who <B></B><FONT SIZE="-1"><B>HAVE</B></FONT><B></B> to have the old
|
|
interface, which uses a comparison function rather than a key generating
|
|
function.
|
|
<P>
|
|
|
|
Because each of the lines in one array have to be compared with each
|
|
of the lines in the other array, this does M*N comparisons. This can
|
|
be very slow. I clocked it at taking 18 times as long as the stock
|
|
version of Algorithm::Diff for a 4000-line file. It will get worse
|
|
quadratically as array sizes increase.
|
|
<A NAME="lbAD"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use Algorithm::DiffOld qw(diff LCS traverse_sequences);
|
|
|
|
@lcs = LCS( \@seq1, \@seq2, $comparison_function );
|
|
|
|
$lcsref = LCS( \@seq1, \@seq2, $comparison_function );
|
|
|
|
@diffs = diff( \@seq1, \@seq2, $comparison_function );
|
|
|
|
traverse_sequences( \@seq1, \@seq2,
|
|
{ MATCH => $callback,
|
|
DISCARD_A => $callback,
|
|
DISCARD_B => $callback,
|
|
},
|
|
$comparison_function );
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>COMPARISON FUNCTIONS</H2>
|
|
|
|
|
|
|
|
Each of the main routines should be passed a comparison function. If you
|
|
aren't passing one in, <B>use Algorithm::Diff instead</B>.
|
|
<P>
|
|
|
|
These functions should return a true value when two items should compare
|
|
as equal.
|
|
<P>
|
|
|
|
For instance,
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
@lcs = LCS( \@seq1, \@seq2, sub { my ($a, $b) = @_; $a eq $b } );
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
but if that is all you're doing with your comparison function, just use
|
|
Algorithm::Diff and let it do this (this is its default).
|
|
<P>
|
|
|
|
Or:
|
|
<P>
|
|
|
|
|
|
|
|
<PRE>
|
|
sub someFunkyComparisonFunction
|
|
{
|
|
my ($a, $b) = @_;
|
|
$a =~ m{$b};
|
|
}
|
|
|
|
@diffs = diff( \@lines, \@patterns, \&someFunkyComparisonFunction );
|
|
|
|
</PRE>
|
|
|
|
|
|
<P>
|
|
|
|
which would allow you to diff an array <TT>@lines</TT> which consists of text
|
|
lines with an array <TT>@patterns</TT> which consists of regular expressions.
|
|
<P>
|
|
|
|
This is actually the reason I wrote this version --- there is no way
|
|
to do this with a key generation function as in the stock Algorithm::Diff.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">NOTE</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">COMPARISON FUNCTIONS</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|