use strict; use warnings; use Time::Local (); my $file_name = shift(@ARGV); open(LOG_FH, '<', $file_name) or die("...$/"); open(TMP_FH, '>', $file_name.'.tmp') or die("...$/"); # Might want to clear the hours, minutes and secs from $old. my $old = time - 90*24*60*60; while (<LOG_FH>) { my ($y, $m, $d) = /...(...)...(...)...(...).../; my $date = Time::Local::timelocal(0, 0, 0, $d, $m-1, $y); last if $date > $old; } do { print TMP_FH $_; } while (<LOG_FH>); close(LOG_FH); close(TMP_FH); unlink($file_name); rename($file_name.'.tmp', $file_name);
Replace ...s with appropriate code. Off the top of my head. There may be a better way. Doesn't lock. Untested.
Actually, Forget everything I said and run Logfile::Rotate as a cron job every 90 days.
Update: I forgot that you specified the date format. Time::ParseDate would probably be of more use than Time::Local.
In reply to Re: Dates! Log Files! Help!
by ikegami
in thread Dates! Log Files! Help!
by rementis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |