Reputation: 1982
I have a use case where I am writing to a file directly and wanted it to rotate automatically as log files do.
One solution I have in mind was to check file size before every write and if size exceed move it to filename.1 (and other files to increment there last count and delete last file if it is more than required number of files).
Is there better way to do this?
Please note I am writing this to file only once per invocation of my process.
Upvotes: 0
Views: 260
Reputation: 126772
The problem has already been solved. CPAN modules Logfile::Rotate
or File::Write::Rotate
have been created exactly for this purpose
Unfortunately I have used neither, and so can't offer an opinion about which of them is the best choice for you
Upvotes: 5