perlquestion
ybiC
<!-- Save 2 files' diff as 3rd file -->
The following chunk is intended to parse 2 logfiles for their diff, and write the results as a third file. One origianl logfile
contains combined STDOUT+STDERR and the other contains only STDERR.
<p>
But it doesn't do that at all. 8^( Rather, the resulting <i>(small-relative-to-either-original log)</i> file contains an
out-of-order hodgepodge from both originals.
</p>
<p>
What, praytell, am I doing wrong here? [davorg]'s [cpan://Array::Compare] doesn't look to do what I need. I've looked at
[bikeNomad]/[Dominus]' [cpan://Alorithm::Diff], but don't make heads or tails of it.
</p>
<code>#!/usr/bin/perl -w
# rlog.pl
$|++; # stdout hot
use strict; # avoid d'oh! bugs
require 5; # for following modules
my $logDir = '/cygdrive/c/Rsync/logs';
my $allLog = "$logDir/200203021258.all";
my $errLog = "$logDir/200203021258.err";
my $fileLog = "$logDir/200203021258.fil";
# slurp two existing logs into arrays:
open ERRLOG, "$errLog" or die "Error opening $errLog: $!";
my @err = <ERRLOG>;
close ERRLOG;
open ALLLOG, "$allLog" or die "Error opening $allLog: $!";
my @all = <ALLLOG>;
close ALLLOG;
# create @file from diff of ERR and ALL:
my %count;
my @file;
$count{$_}++ for ( @all, @err );
for ( keys %count ) {
push @file, $_ unless ( $count{$_} == 2 );
}
# write $fileLog from @file:
open FILELOG, "> $fileLog" or die "Error opening $fileLog: $!";
for (@file) {
print FILELOG;
}
close FILELOG;
</code>
<br> cheers,
<br> Don
<br> <i>striving toward <a href="http://prometheus.frii.com/~gnat/yapc/2000-stages/">Perl Adept</a></i>
<br> <font size="-2">(it's pronounced "why-bick")</font>