Actually, these are the rountines from the auto-delete script!
Maybe I'm doing something else wrong?
See anything else in here that's out of kilter:
# Required Files to make this file work.
# Required Files to make this file work.
require "/web/hosted/philnet/cgi-bin/db/default.cfg";
# Change to the correct field number
my $removeby_field = 22;
# Change to the correct field number
my $dateadded_field = 20;
my $today = &date_to_unix(&get_date);
my (@lines, @values);
print "Content-type: text/plain\n\n";
open (DB, $db_file_name) or ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) {
flock (DB, 1);
}
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or ("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 ($_);
print "Comparing: '$today' vs '$values[$removeby_field]' ... \n";
if ($today > (&date_to_unix($values[$dateadded_field]) + (86400 * $values[$removeby_field]))) {
print "Record(s) Deleted\n";
next;
}
print DB $_, "\n";
}
close DB;
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yyyy".
# Warning: If you change the default format, you must also modify the
# date_to_unix subroutine below which converts your date format into a # unix time in seconds for sorting purposes.
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$mon += 1;
($mon < 10) and ($mon = "0$mon");
$year += 1900;
return "$mon\/$day\/$year";
}
sub date_to_unix {
# ------------------------------------------------------
# This routine must take your date format and return the time a la UNIX # time. Some things to be careful about..int your values just in case
# to remove spaces, etc. catch the fatal error timelocal will generate # if you have a bad date..don't forget that the month is indexed from
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
------------------
Michael Liimatta, Director of Education
International Union of Gospel Missions
1045 Swift, Kansas City, MO 64116 USA
Phone: 816.471.8020 - FAX 816.471.3718
http://
www.iugm.org/michael.html