Seems like the most straight-forward way...and to do it one continuous pass, would be to:

1. Get Filename 2. Extract unique part of file to a $uniqueId variable 3. Keep unique $uniqueId as key to hash 4. Get date-time stamp of file 5. If $uniqueId key doesn't ye exist in hash then store filename and date-time stamp in hash (perhaps as 'filename':'date-time stamp' to make it easy and quick to use split(":",$uniqueIds{$uniqueId}) to recover the parts) at that $uniqueId key, ELSE Get the filename and date-time stamp already in hash at that $uniqueId; Compare date-time (probably using CPAN module to make this easy and simple) already in hash at $uniqueId key; Store new filename and date-time stamp into hash if new date-time is later than old one and Delete the old file that was idetified at the old entry in the hash, OTHERWISE, Delete this file. 6. Repeat #5 until all files processed.

This will leave the names and date-time stamps of the 'latest' (or 'newest') filenames in the hash at the end of the run and will also leave only the newest files in the directory.

ack Albuquerque, NM

In reply to Re: Delete the file with checking the value by ack
in thread Delete the file with checking the value 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.