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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

But it doesn't do that at all.   8^(   Rather, the resulting (small-relative-to-either-original log) file contains an out-of-order hodgepodge from both originals.

What, praytell, am I doing wrong here?   davorg's Array::Compare doesn't look to do what I need.   I've looked at bikeNomad/Dominus' Alorithm::Diff, but don't make heads or tails of it.

#!/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;

    cheers,
    Don
    striving toward Perl Adept
    (it's pronounced "why-bick")

In reply to Save 2 files' diff as 3rd file by ybiC

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 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? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2022-05-22 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?