I'm trying to parse some log files and print reports for each day. The problem is the current way I'm detecting a new day, the very last day in the log file never gets printed.
I'm sure I'm overlooking an incredibly simple solution, but I've not found it yet.
#!/usr/bin/perl -w
use strict;
my $date;
my $lastdate = '';
while(<DATA>){
$date = $_;
if (($lastdate ne $date) && ($lastdate ne '')){
# print $lastdate report here
print "$. $_";
}
$lastdate = $date;
}
__DATA__
10
10
10
11
11
11
12
12
12
Update Of course the snippet posted above is an over simplification of the problem. Thanks to all for the ideas.
The solution was given in mifflin's code but what drove it home was when GrandFather said "The bug fix is to let the while loop run one more itteration after finding the end of the file."
I'm parsing maillog files to produce a SpamAssassin report. I foolishly started with someone elses code that did not work, did not use strict, did not use warnings.. I would have been better off I think to do the whole thing from scratch.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.