I may be misunderstanding you, but if I guess right you want to READ every line in the text-files (which are like some sort of log-files it seems), extract the date in each of these lines, compare that date to today's date and if older than 1 month, delete that line in the file and save it in some archive file.

For date parsing and comparisons have a look at Date::Manip which is the Rolls Royce of date-modules, what it lacks in raw speed, it delivers in convenience.

Generally, you could do as follows:

  1. open your archive file for adding to it
  2. open the first of your files for reading
  3. read this file line by line
  4. check the date in each line and if older than one month write it to the archive file, else push it onto a stack for temporary storage
  5. At the end of the file; close it and reopen it for writing (this will clear the contents of this file!); else goto step 3
  6. now write your temporary stack to this file (hint: use foreach)
  7. close the file
  8. open your next file; if no more files remain: close your archive file; else goto step 3

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law


In reply to Re: Comparing Dates by CountZero
in thread Comparing Dates by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.