Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found