in reply to Delete the file with checking the value
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.
|
|---|