Hi all,
I'm writing a script that is supposed to keep the most recent seven days of a
log file and discard the rest. The only problem I'm facing now is that I need
it to handle end of the month conversions from say, March 31st to April 1st.
Here's a snippet of the code I have:
For note: CurDay is an incremental value that starts out at a value
7 less than today's date and builds up gradually until a match takes place.
foreach $file (@filenames) {
open (IN,"$file") || die "Cannot open \"$file\" for input: $!.
+\n";
@log_in = <IN>;
close IN;
print "Processing $file . . .\n";
init_vars();
foreach $ln (@log_in) {
if ($alreadymatched) {
$logfile[$count] = $ln;
$count++;
} else {
do {
if ($ln =~ /^$month:$curday/) {
$alreadymatched = 1;
$logfile[0] = $ln;
}
$curday++;
} until ($alreadymatched);
}
}
open (IN,">done.$file") || die "Cannot open \"$file\" for outp
+ut: $!.";
foreach $writelog (@logfile) {
print IN $writelog;
}
close IN;
}
The problem I'm facing is that tomorrow, when it tries to count from 7 days ago to tomorrow, although it will
reach 1, it will not pattern match what I want it to in the file. I need to find a way to get
CurDay to go from 25 26 27 28 29 30 31 1. The same will hold true for the next month as well, of course
I'm told there's a Julian Date function or library out there but cannot seem to find it.
I'm very much a novice at this and would appreciate any help that you all can give.
If you can solve this w/o getting too obfuscated (such that a novice like myself can understand it) I'd appreciate
that as well.
Thanks!
Xao
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.