#!/usr/bin/perl -w

use strict;

use HTML::Diff;

unless( @ARGV == 2 ) {
    print <<EOF;
usage: htmldiff <file1.html> <file2.html>
EOF
    exit;
}

my ($file1, $file2);
{
    undef $/;
    open FH, "<$ARGV[0]" or die "Cannot open $ARGV[0] for reading";
    $file1= <FH>;
    close FH;
    open FH, "<$ARGV[1]" or die "Cannot open $ARGV[1] for reading";
    $file2= <FH>;
    close FH;
}

my @diff= grep $_->[0] ne "u", @{ HTML::Diff::html_word_diff($file1, $file2) };

for (@diff) {
    if( $_->[0] eq "c" ) {
        print "!-  $_->[1]\n!+  $_->[2]\n";
    }
    else {
        print "$_->[0]$_->[0]  ", $_->[0] eq "+" ? $_->[2] : $_->[1], "\n";
    }
}

