Hello... I am having some trouble with a foreach loop... I think my if-logic is flawed... I was wondering if anyone mite see my mistake..? I am processing date selected files from a directory... Trying to process the logfile from today and yesterday... ie. files with a filestamp of 20030312 & 20030313... My if-logic failure seems to be processing the log file more than once. Do I need to exit from the foreach loop before I close the if {} ..?
I can provide more input to this question if needed...
Thank you... Darrick...
@contents contains filenames to be processed
$pth path to the directory
$logfile is the assembled path/file name
&filestamp is a sub to retrieve ->mtime (File::stat)
$filestamp is retrieved filestamp ie. '20030313'
$datestamp is current day stamp ie. '20030313'
foreach $content (@contents) {
#print "$content\n";
$logfile = "$pth" . '\\' . "$content";
#print "$logfile ";
#print "$datestamp\n";
foreach ($logfile) {
&filestamp ('$logfile');
if ($filestamp == $datestamp) {
print "$logfile --> ";
print "Is current, processing\n";
open(FILE, "$logfile"); # open logfile for reading
&do_file_processing_sub;
close(FILE);
}
elsif ($filestamp == ($datestamp -1)) {
print "$logfile --> ";
print "Is one day old, processing\n";
open(FILE, "$logfile"); # open logfile for reading
&do_file_processing_sub;
close(FILE);
}
else {print "$logfile is out of date range\n";}
}
}
}
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.