in reply to Find and Compressing log files.
then loop through the resultant array, using something like Date::Parse to convert the dates to unix time (ex: "Thu Jan 26 10:04:56 2006" becomes 1138291496), and splice off any elements older than the given time:open(ERRLOG,"myerror.txt"); @file = <ERRLOG>;
then just output the array (whats left of it, anyway) back to the file. Note that this code hasnt been tested, by the way.foreach $line (0..$#file) { # grab the date and dump into $date $date = $1 if $file[line] =~ m/^\[(.*?)\]/; # parse it to unix time $date = str2time($date); # method from Date::Parse # if its older than a month (30 days specifically) if($date < (time-2592000)) # 2592000 secs = 30 days { splice @file,$line,1; } }
__________
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
- Terry Pratchett
|
|---|