Hi there
I'm using the auto_delete mod. I wanna change the value of a specific field instead of deleting the current record (even it's not really make sense though ). Plus I wanna save the modified record to the db file as well. Could you guys please gimme some ideas how to make use of the following code? Thank you so much!!
Aladdin
sub auto_delete {
# ------------------------------------------
# Automatically removes entries older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.
my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
if ($removeby > &date_to_unix($values[$date_field])) {
# next;
}
print DB $_, "\n";
}
close DB;
}
I'm using the auto_delete mod. I wanna change the value of a specific field instead of deleting the current record (even it's not really make sense though ). Plus I wanna save the modified record to the db file as well. Could you guys please gimme some ideas how to make use of the following code? Thank you so much!!
Aladdin
sub auto_delete {
# ------------------------------------------
# Automatically removes entries older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.
my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
if ($removeby > &date_to_unix($values[$date_field])) {
# next;
}
print DB $_, "\n";
}
close DB;
}