#!/usr/bin/perl -w # Visual diff in Tk # Copyright Clinton Pierce 2001 # Re-distributable under the same terms as Perl itself use strict; use Tk; use Tk::Font; use Algorithm::Diff qw(traverse_sequences); die "$0: 2 Args" unless (@ARGV == 2); sub fill { local(*A,$/); open(A, $_[0]) || die "$_[0]: $!"; # Changing the split re changes how the document # is diff'd. Using \b goes word-by-word, using # \n goes line-by-line, etc. return split(/\b/, <A>); } my $mw=new MainWindow; my $tb=$mw->Scrolled('Text')->pack(-expand => 1, -fill => 'both'); my $fn=$mw->Font(); my $fo=$mw->Font(-overstrike => 1); my @a1=fill(shift); my @a2=fill(shift); traverse_sequences(\@a1, \@a2, { MATCH => sub { $tb->insert('end', $a1[$_[0]], 'match'); }, DISCARD_A => sub { $tb->insert('end', $a1[$_[0]], 'disca'); }, DISCARD_B => sub { $tb->insert('end', $a2[$_[1]], 'discb'); }, }); $tb->tagConfigure('match', -foreground => 'black', -font => $fn); $tb->tagConfigure('disca', -foreground => 'red', -font => $fo); $tb->tagConfigure('discb', -foreground => 'blue', -font => $fn); $mw->MainLoop;

In reply to Visual diff in Tk by clintp

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.