This script uses tachyon's color coded diff code.
Tachyon's script was hilighting the lines that were differents between 2 files. This script hilights only the part of the line that is different from the line in the other file (just like emacs' compare 2 file does)
traverse_sequence is the only function i changed, that's why get and escape html functions are not re-printed here.
html output is netscape 4+ and ie4+ compliant
# stolen at http://www.perlmonks.org/index.pl?node_id=115928 # as well as the get and escapeHTML functions # get options and file contents as array refs my $old = get($old_file, 1, 1); my $new = get($file, 1, 1); open (SDIFF, "> $result_file") || &Error("Can't open $result_file: + $!"); # print out the colour coded diff - common code is black # code in $old_file but not $new_file is (bg) red # code in $new_file but not $old_file is (bg) green print SDIFF "<div><table align=center bgcolor=white celpadding=0 c +ellspacing=0><tr><th>Color Key:</th></tr>"; print SDIFF "<tr><td bgcolor=lightcoral>".escapeHTML($old_file)."< +/td></tr>"; print SDIFF "<tr><td bgcolor=darkseagreen>".escapeHTML($file)."</t +d></tr>\n"; print SDIFF "</table><br><table celpadding=0 cellspacing=0>"; my $a; my $b; my $a_lines; my $b_lines; traverse_sequences({ MATCH => sub { if ($a) { if ($b) { #$b_lines to compare with $a_lines # print a_lines with hilited diffs print SDIFF "<tr><td bgcolor=lightcoral>"; my @a_table=split(/ */, $a_lines); my @b_table=split(/ */, $b_lines); traverse_sequences( { MATCH => sub { print SDIFF escapeHTM +L($a_table[$_[0]]) }, DISCARD_A => sub { print SDIFF "<span st +yle=\"background-color:yellow\">" . escapeHTML($a_table[$_[0]])."</sp +an>"}, DISCARD_B => sub { print SDIFF "" }, }, \@a_table, \@b_table,); print SDIFF "</td></tr>"; # now print b_lines with hilited diffs print SDIFF "<tr><td bgcolor=darkseagreen>"; traverse_sequences( { MATCH => sub { print SDIFF escapeHTM +L($b_table[$_[1]]) }, DISCARD_A => sub { print SDIFF ""}, DISCARD_B => sub { print SDIFF "<span st +yle=\"background-color:yellow\">" . escapeHTML($b_table[$_[1]])."</sp +an>" }, }, \@a_table, \@b_table,); print SDIFF "</td></tr>"; $b=0; $b_lines=""; } else { print SDIFF "<tr><td bgcolor=lightcoral>".escap +eHTML($a_lines)."</td></tr>"; } $a=0; $a_lines=""; } else { if ($b) { print SDIFF "<tr><td bgcolor=darkseagreen>".esc +apeHTML($b_lines)."</td></tr>"; $b=0; $b_lines=""; } } print SDIFF "<tr><td bgcolor=white>".escapeHTML($ol +d->[$_[0]])."</td></tr>" }, DISCARD_A => sub { $a++; $a_lines.=$old->[$_[0]]; }, DISCARD_B => sub { $b++; $b_lines.=$new->[$_[1]]; }}, $old, $new, ); print SDIFF "</table>\n"; close SDIFF; last if $caught_sigint; }

In reply to color coded diff (the return) by iza

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.