If I underastand you correctly, you have a program that does
two things: first it appends data to a file named after today's
date, eg a log file; second, if that file doesn't exist, then it first
finds the most recent file with an older date in its filename, then creates the new file.
I would recomment choosing a filename format that sorts
alphabetically the same as cronologically, eg 2004.05.11.txt.
Then all you need to do is read in the current directory,
do a reverse sort on the filenames, and pick the first, eg
opendir D, '.';
@files = reverse sort grep $_ ne '.' && $_ ne '..', readdir D;
if (@files) {
email($files[0]);
}
If you can't make your filenames sort like that, then
you'll need to take the extra step of splitting apart the
filename, eg
@files = map { $_->[0] }
sort { $b->[1] <=> $a[1] }
map { /^(..)(..)(..)/; [ $_, "$3$2$1" ] }
grep $_ ne '.' && $_ ne '..',
readdir D;
(The above is known as a Schwartzian transform)
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.