????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.55 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/libalgorithm-diff-perl/examples/ |
Upload File : |
#!/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 => '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 => 'onlyB' }, $b[$ib] ), "\n";
}
# MAIN PROGRAM
# Check for two arguments.
print "usage: $0 file1 file2 > diff.html\n" if @ARGV != 2;
$tabstop = 4; # For Text::Tabs
# Read each file into an array.
open FH, $ARGV[0];
@a = <FH>;
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
DISCARD_B => \&only_b, # callback on B-only
}
);
print end_html();