learner
learner

Reputation: 1982

Rotate a normal file after certain size like a log file in perl

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

Answers (1)

Borodin
Borodin

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

Related Questions