MissPerl:
While awaiting responses on my question, I whipped this up. You could use it as a base to work from:
$ cat ~/bin/diffident_html.pl
#!env perl
#
# diffident_html.pl <FName> <FName>
#
# Build a dumb HTML table showing the diff (via Algorithm::Diff) of tw
+o files
#
use strict;
use warnings;
use Algorithm::Diff;
my $LFName = shift // die "Expected two file names!";
my @lfile = readfile($LFName);
my $RFName = shift // die "Expected *TWO* file names!";
my @rfile = readfile($RFName);
my $diff = Algorithm::Diff->new( \@lfile, \@rfile );
$diff->Base(1);
print qq{<html><body><table border="1">\n};
print qq{<tr><th colspan="2" align="left" bgcolor="#c0c0c0">$LFName</t
+h>}
. qq{<th colspan="2" align="left" bgcolor="#c0c0c0">$RFName</t
+h></tr>\n};
print qq{<tr><th width="1%" align="right" bgcolor="#c0c0c0">#</th>}
. qq{<th width="49%" align="left" bgcolor="#c0c0c0">Source</th
+>}
. qq{<th width="1%" align="right" bgcolor="#c0c0c0">#</th>}
. qq{<th width="49%" align="left" bgcolor="#c0c0c0">Source</th
+></tr>\n};
while ($diff->Next()) {
if ($diff->Same()) {
# Left and Right file have a block of identical lines
print qq{<tr><td colspan="4" align="center">. . .&nb
+sp;. }
. qq{ block of matching lines . . . .</td><
+/tr>\n};
next;
}
my ($min1, $min2) = $diff->Get(qw( Min1 Min2 ));
my @L = $diff->Items(1);
my @R = $diff->Items(2);
while (@L or @R) {
print qq{<tr>};
if (@L) {
print qq{<td align="right">$min1</td><td align="left">$L[0
+]</td>};
++$min1;
shift @L;
}
else {
print qq{<td colspan="2" bgcolor="#c0c0c0">};
}
if (@R) {
print qq{<td align="right">$min2</td><td align="left">$R[0
+]</td>};
++$min2;
shift @R;
}
else {
print qq{<td colspan="2" bgcolor="#c0c0c0">};
}
print qq{</tr>\n};
}
}
print qq{</table></body></html>\n};
sub readfile {
my $fname = shift;
open my $FH, '<', $fname or die "Can't open file $fname: $!\n";
return <$FH>;
}
I simply took an Anonymous Monk's suggestion to use Algorithm::Diff to get the differences between two files, and from that glued the data together into an HTML table. If you wanted to *really* use it, you'd probably want to use a template handling package, work through the error cases, etc.
...roboticus
When your only tool is a hammer, all problems look like your thumb.