3 # `Diff' program in Perl
4 # Copyright 1998 M-J. Dominus. (mjd-perl-diff@plover.com)
6 # This program is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
10 use Algorithm::Diff qw(diff);
12 bag("Usage: $0 oldfile newfile") unless @ARGV == 2;
14 my ($file1, $file2) = @ARGV;
16 # -f $file1 or bag("$file1: not a regular file");
17 # -f $file2 or bag("$file2: not a regular file");
19 -T $file1 or bag("$file1: binary");
20 -T $file2 or bag("$file2: binary");
22 open (F1, $file1) or bag("Couldn't open $file1: $!");
23 open (F2, $file2) or bag("Couldn't open $file2: $!");
29 $diffs = diff(\@f1, \@f2);
30 exit 0 unless @$diffs;
32 foreach $chunk (@$diffs) {
34 foreach $line (@$chunk) {
35 my ($sign, $lineno, $text) = @$line;
36 printf "%4d$sign %s\n", $lineno+1, $text;