<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
# diffs two files and writes an HTML output file.
use strict;
use CGI qw(:standard :html3);
use Algorithm::Diff 'traverse_sequences';
use Text::Tabs;

my ( @a, @b );

# Take care of whitespace.
sub preprocess
{
	my $arrayRef = shift;
	chomp(@$arrayRef);
	@$arrayRef = expand(@$arrayRef);
}

# This will be called with both lines are the same
sub match
{
	my ( $ia, $ib ) = @_;
	print pre( $a[$ia] ), "\n";
}

# This will be called when there is a line in A that isn't in B
sub only_a
{
	my ( $ia, $ib ) = @_;
	print pre( { -class =&gt; 'onlyA' }, $a[$ia] ), "\n";
}

# This will be called when there is a line in B that isn't in A
sub only_b
{
	my ( $ia, $ib ) = @_;
	print pre( { -class =&gt; 'onlyB' }, $b[$ib] ), "\n";
}

# MAIN PROGRAM

# Check for two arguments.
print "usage: $0 file1 file2 &gt; diff.html\n" if @ARGV != 2;

$tabstop = 4;    # For Text::Tabs

# Read each file into an array.
open FH, $ARGV[0];
@a = &lt;FH&gt;;
close FH;

open FH, $ARGV[1];
@b = &lt;FH&gt;;
close FH;

# Expand whitespace
preprocess( \@a );
preprocess( \@b );

# inline style
my $style = &lt;&lt;EOS;
	PRE {
		margin-left: 24pt; 
		font-size: 12pt;
	    font-family: Courier, monospaced;
		white-space: pre
    }
	PRE.onlyA { color: red }
	PRE.onlyB { color: blue }
EOS

# Print out the starting HTML
print

  # header(),
  start_html(
	{
		-title =&gt; "$ARGV[0] vs. $ARGV[1]",
		-style =&gt; { -code =&gt; $style }
	}
  ),
  h1(
	{ -style =&gt; 'margin-left: 24pt' },
	span( { -style =&gt; 'color: red' }, $ARGV[0] ),
	span(" &lt;i&gt;vs.&lt;/i&gt; "),
	span( { -style =&gt; 'color: blue' }, $ARGV[1] )
  ),
  "\n";

# And compare the arrays
traverse_sequences(
	\@a,    # first sequence
	\@b,    # second sequence
	{
		MATCH     =&gt; \&amp;match,     # callback on identical lines
		DISCARD_A =&gt; \&amp;only_a,    # callback on A-only
		DISCARD_B =&gt; \&amp;only_b,    # callback on B-only
	}
);

print end_html();
</pre></body></html>