|Keep It Simple, Stupid|
rotating files, is there a better way?by greenFox (Vicar)
|on Apr 04, 2001 at 06:38 UTC||Need Help??|
greenFox has asked for the
wisdom of the Perl Monks concerning the following question:
As part of a much larger script I need to rotate thousands of files, ie move each one to the next higher number with a maximum of 10, image.9.jpg is the highest kept. The code probably explains it better, here is what I originally wrote-
which works but has to check for the existence of a lot of files which potentially don't exist, ie if the highest file is image.4.jpg it still checks for the existance of 8 down. I tried to refine this a bit and ended up with-
which also works but is not very pretty. So I was wondering if any-one could see a better way?
rename_and_log() does what it says :) Logs the transaction to a file and rename()'s with error checking, unless we are in "test" mode in which case it tells instead of doing.Thanks.
I was thinking of posting this as a golf exercise but I wasn't sure if a) it was worthy and b) if any code resulting from a golf exercise would be useable in production :-) <- note the smiley!