jwebste1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone,
I'm somewhat new to perl and have been manually (visually) comparing a text import file consisting of a trailer that indicates the number of "records" that should be imported into an application. I then have to check a text "log/report" that indicates the actual Total Records imported ## into the system. I probably could have mulled through this one on my own but the caveat is there are three types of records (3 place holders in the trailer) and 3 corresponding "Total Records Imported :##" entries in the generated log/report. There is nothing unique to map to in the report except that the sequence will remain the same i.e. trailer1 placeholder will be the first "Total records imported :##" entry and trailer2 place holder will be the second "Total Records imported entry and so on". The "Total Records imported:##" and Trailer# place holder should be equal to one another (hence the visual checking :) I have searched hi and lo for help but am being pulled mostly to source code comparison utilities which doesn't seem to correlate to me needs. Any help would be much much appreciated!

Here is an example of the Trailer thread

T0000000000000018700000000011345000000000000000000000

(in terms of orientation it is the very last line in the record) Here is an example of the corresponding log/record

output: Total Records Processed: 187

I know from the trailer (Character space 18 to 11 is used for A records and the other number is the B Record or Character 33 to 28) so the first Total Record found in the log should be followed by 187 (A record) and the 2nd Total Record should correspond to the B record number). Ideally I would like to email myself either a successful or failure message.

Reformatted to match original input as best as could be determined by davido.

  • Comment on Need to compare import Trailer to Result Log

Replies are listed 'Best First'.
Re: Need to compare import Trailer to Result Log
by holli (Abbot) on Jan 25, 2005 at 19:50 UTC
    would you be some kind to give us some sample data? Itīs hard for us to assemble code "out of the blue". But this could get you started (compiles but oviously untested).
    use strict; use warnings; my @trailer; my @logfile; open IN, "trailer" or die $!; while (<IN>) { push @trailer, $1 if /Trailer(\d+)/; } close IN; open IN, "logfile" or die $!; while (<IN>) { push @logfile, $1 if /Total Records Imported :(\d+)/; } close IN; die "number of imports doesnīt match!\n" if @trailer != @logfile; for (0..$#trailer) { print "import no. $_: ", ($trailer[$_] == $logfile[$_] ? "ok\n" : +"not ok\n"); }
    Update:
    given the sample data you provided (hint: if you make a significant update to your node, make it visisble) i changed my code above as follows. It should do the trick:
    use strict; use warnings; my @trailer; my @logfile; my $trailer; open IN, "trailer" or die $!; while (<IN>) {$trailer = $_} close IN; @trailer = (substr($trailer,10,8), substr($trailer,24,8)); @trailer = map { s/^0+//; $_ } @trailer; open IN, "logfile" or die $!; while (<IN>) { push @logfile, $1 if /Total Records Processed: (\d+)/; } close IN; die "number of imports doesnīt match!\n" if @trailer != @logfile; for (0..$#trailer) { print "import no. $_: ", ($trailer[$_] == $logfile[$_] ? "ok\n" : +"not ok\n"); }

    holli, regexed monk