Algorithm-Diff
view release on metacpan or search on metacpan
-c do a context diff with 3 lines of context
-C do a context diff with 'lines' lines of context (implies -c)
-e create a script for the ed editor to change oldfile to newfile
-f like -e but in reverse order
-u do a unified diff with 3 lines of context
-U do a unified diff with 'lines' lines of context (implies -u)
-q report only whether or not the files differ
-i ignore differences in Upper/lower-case
-w ignore differences in white-space (space and TAB characters)
By default it will do an "old-style" diff, with output like UNIX diff
ENDUSAGE
my $Context_Lines = 0; # lines of context to print. 0 for old-style diff
my $Diff_Type = "OLD"; # by default, do standard UNIX diff
my ($opt_c, $opt_u, $opt_e, $opt_f, $opt_q, $opt_i, $opt_w);
my $compareRoutineRef = undef;
while ($ARGV[0] =~ /^-/) {
my $opt = shift;
last if $opt eq '--';
if ($opt =~ /^-C(.*)/) {
$Context_Lines = $1 || shift;
$opt_c = 1;
$Diff_Type = "CONTEXT";
htmldiff.pl view on Meta::CPAN
close FH;
open FH, $ARGV[1];
@b = <FH>;
close FH;
# Expand whitespace
preprocess( \@a );
preprocess( \@b );
# inline style
my $style = <<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 => "$ARGV[0] vs. $ARGV[1]",
-style => { -code => $style }
}
),
h1(
{ -style => 'margin-left: 24pt' },
span( { -style => 'color: red' }, $ARGV[0] ),
span(" <i>vs.</i> "),
span( { -style => 'color: blue' }, $ARGV[1] )
),
"\n";
# And compare the arrays
traverse_sequences(
\@a, # first sequence
\@b, # second sequence
{
MATCH => \&match, # callback on identical lines
DISCARD_A => \&only_a, # callback on A-only
( run in 0.458 second using v1.01-cache-2.11-cpan-49f99fa48dc )