## this is the framework: ## One of the two code snippets below are ## substituted for ### DIFF ALGORITHM HERE.. #!/usr/bin/perl use strict; use lib "/Users/allasso/AWS/utility/cpan/lib/perl5/site_perl"; require Algorithm::Diff; use Time::HiRes qw( time ); my($source_path_1, $source_path_2) = @ARGV; my $holdRS = $/; local $/; if (! open(FH, $source_path_1)) { print "unable to open source file 1: $source_path_1\n"; } my $filestring_1 = ; $/ = $holdRS; close(FH); $holdRS = $/; local $/; if (! open(FH, $source_path_2)) { print "unable to open source file 2: $source_path_2\n"; } my $filestring_2 = ; $/ = $holdRS; close(FH); $filestring_1 =~ s@\s+@\n@g; $filestring_2 =~ s@\s+@\n@g; my $time = time(); for my $count (0..999) { ### DIFF ALGORITHM HERE.. } my $time_4sig = time() - $time + .005; $time_4sig =~ s@^(.....).*@$1@; print STDERR "\n\net: ".$time_4sig."\n"; exit; ## this is the CPAN Algorithm::Diff code: my @seq1 = split(/\n/, $filestring_1); my @seq2 = split(/\n/, $filestring_2); my $diff = Algorithm::Diff->new( \@seq1, \@seq2 ); $diff->Base( 1 ); # Return line numbers, not indices while( $diff->Next() ) { next if $diff->Same(); my $sep = ''; if( ! $diff->Items(2) ) { printf "%d,%dd%d\n", $diff->Get(qw( Min1 Max1 Max2 )); } elsif( ! $diff->Items(1) ) { printf "%da%d,%d\n", $diff->Get(qw( Max1 Min2 Max2 )); } else { $sep = "\n---\n"; printf "%d,%dc%d,%d\n", $diff->Get(qw( Min1 Max1 Min2 Max2 )); } print "< $_" for $diff->Items(1); print $sep; print "> $_\n" for $diff->Items(2); } ## this is the diffutils code: if (! open(FH, ">/tmp/diff_774885959483_1")) { print "unable to open temporary file\n"; } print FH "$filestring_1"; close (FH); if (! open(FH, ">/tmp/diff_774885959483_2")) { print "unable to open temporary file\n"; } print FH "$filestring_2"; close (FH); print "$source_path_1 ::: $source_path_2\n"; print `diff --suppress-common-lines -y /tmp/diff_774885959483_1 /tmp/diff_774885959483_2`;