#!/usr/bin/perl
#----------------------------------------
# Compare two binary files
# See comments below for modifications
#----------------------------------------
$file1 = $ARGV[0];
$file2 = $ARGV[1];
$size1 = -s $file1 ;
open(FILE1,"<$file1") or die "Input file: Cannot open file1\n\n";
open(FILE2,"<$file2") or die "Input file: Cannot open file2\n\n";
$i = 0 ;
$j = 0 ;
while ($i < $size1 )
{
$i ++ ;
$ch1 = getc(FILE1);
$ch2 = getc(FILE2);
print $ch1 . $ch2 . "\n" ;
if (!($ch1 eq $ch2))
{
print "Difference detected at character: " . $i . "\n" ;
$j ++ ;
}
# diff limiter: edit this line to modify
# the number of differences before exiting program
if ($j > 15)
{
exit ;
}
}
close(FILE1);
close(FILE2);
|
|