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; }

In reply to Poor man's diff by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.