I need to remove entries from a flatfile DB that are over 30 days old, but what happens is the whole file gets wiped (definitely not a good thing...)
Any suggestions are greatly appreciated....
Jim
The code I am using is:
Any suggestions are greatly appreciated....
Jim
The code I am using is:
Code:
sub delete_old {
$current_time = time;
$delete_date = $current_time - ($days * 86400);
open (TEMP, ">cards_temp") || &CgiError ("Could not open cards_temp");
flock (TEMP, 2);
open (CARD, "$cards") || &CgiError ("Could not open $cards");
flock (CARD, 2);
while (<CARD>) {
($number, $from, $from_email, $message, $to, $image, $layout, $date_time, $date) = split(/\|/, $_);
if ($delete_date < $date_time) {
print TEMP "$_";
}
}
flock (CARD, 9);
flock (TEMP, 9);
close (TEMP);
close (CARD);
rename ("cards_temp", "$cards");
}