http://www.perlmonks.org?node_id=459572

I have a windows server that I refuse to work on as much as possible, although fortunately it has a copy of Perl 5.6.1 installed. In the process of replacing a batch process that spits out interface files that are imported on another system, I needed to test whether what I was producing was the same.

You cannot, as far as I am aware, tell Text::Diff to ignore trailing blanks as being insignificant. So I whipped up the following poor man's diff to do, well, a poor man's diff (no, I don't have Cygwin installed). It showed me that I had a single field in my new replacement that differs from the original. Tracing things further, I found that the original program had a SQL bug in which table t1 was being joined to table t2 instead of t3. Funnily enough, the comments in the original program said that the select was supposed to be on t3.

Exit one 1314-line C program, to be replaced by a 278-line Perl program (of which 95 lines is an SQL select heredoc).

Note that this diff does not notice, nor does it care, if the files are of different lengths. Additional lines in the longer file will be silently ignored. In certain circumstances, this could be construed as a feature.

#! perl -w # poordiff.pl -- a poor man's diff use strict; my $in1 = shift || die "no first file"; my $in2 = shift || die "no second file"; open IN1, $in1 or die "input $in1: $!\n"; open IN2, $in2 or die "input $in2: $!\n"; my $nr = 0; while( defined( my $r1 = <IN1> ) and defined( my $r2 = <IN2> ) ) { $r1 =~ s/\s+$//; $r2 =~ s/\s+$//; ++$nr; print "files differ at line $nr\n" if $r1 ne $r2; }