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">.&nbsp;.&nbsp;.&nb +sp;. } . qq{ block of matching lines .&nbsp;.&nbsp;.&nbsp;.</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.


In reply to Re: diff vs diff -y by roboticus
in thread diff vs diff -y by MissPerl

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.