Take a look at the file test operators to
find out about the age of a file. Furthermore you will have to
do the removal of the files by hand/perl yourself ...
-- Hofmator
| [reply] |
Sorry it doesn't use Perl, but you could put something
like this in your crontab
0 * * * * find yourdir -mtime +7 | xargs rm
Every hour, it deletes all files in "yourdir" that have
last been modified more than seven days ago.
--bwana147 | [reply] [d/l] |
If you want to find the age of the file, look into the file test
operators -M, -A and -C.
xoxo,
Andy
%_=split/;/,".;;n;u;e;ot;t;her;c; ". # Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'. # http://petdance.com
"hack";print map delete$_{$_},split//,q< andy@petdance.com >
| [reply] |
You probably need a cron job (available on any flavor of UN*X; Host restrictions not included) to run a check on weither or not posts are 7 (or more) days old. It all depends on how you'll be implementing it. I'd recommend a SQL backend (DBI would be nice). If you're gonna use plain files, stat is that nifty file stats function (and yeah -X has -M). if you want to play it safe, you can just ignore old(er) posts and only show newer ones (as in don't delete older posts).
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur. | [reply] [d/l] |
Well, there's nothing to stop you doing this in Perl (read up on 'stat'), but a cron might be simpler (using 'find').
place something like:
find '/usr/home/foobar/' -name '*.add' -mtime +7 -exec rm {} \;
in your crontab.
BTW I don't use *nix much, so don't take this as gospel, more of a very IMHO.
Tom Melly, tom@tomandlu.co.uk
| [reply] |
my $filename = 'abc.def.ghi';
# delete file if too old
if (-M $filename > 7) { unlink($filename) }
else { # do something with file
}
| [reply] [d/l] |
Well, I'm wondering if it might be easier for you to use
a database, as opposed to files. What you could for every
classified ad is have a field for (amongst other things)
the ad itself, and the day it was posted. Whenever it is
posted, just use Perl to generate a datestamp and put it
into that database field. Then every evening, you could
have a cron job to dig through the database and expire (delete?)
entries that are 7 days old.
To use a database this way, you wouldn't even be required to
have a full fledged database server running in the background,
you could use something as simple as CSV files if thats what
you want. OTOH, MySQL and Postgres come pretty cheap :-)
-Eric | [reply] |