http://qs321.pair.com?node_id=297773

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
In Perl is there a program that could delete a file from a database if per example the file is old than 3 months?
Thanks!!

Replies are listed 'Best First'.
Re: Deleting Old Files in a DB.
by mandog (Curate) on Oct 09, 2003 at 00:51 UTC

    Greetings Anonymous Monk

    Your question is a bit vague...

    What do you mean by "file" and "database" ?

    On most UNIX machines you can delete files that are londer than a certain time w/ something like:

    find /tmp -type f -mtime +20 | xargs rm

    On MS windows you can use the find command to locate files older than a certain time & then select them and delete them.

Re: Deleting Old Files in a DB.
by benn (Vicar) on Oct 09, 2003 at 11:41 UTC

    If you're looking for a way of deleting old *records* from an SQL-based DBMS, then you can usually do this with pure SQL (and thus in any language you like that provides DB connections), assuming that you stored the original record-creation time (rec_timestamp, in the example below).

    Therefore, a simple Perl program to do this with MYSQL would look something like...

    use DBI; my $dbh = DBI->connect("DBI:mysql:db_name","user","pass") || die $DBI: +:err; $dbh->do("delete from mytable where to_days(rec_timestamp) < to_days(n +ow()) - 90");
    HTH, Ben.
Re: Deleting Old Files in a DB.
by vek (Prior) on Oct 09, 2003 at 15:30 UTC

    In Perl is there a program that could delete a file from a database...

    Sure there is, once you've written it ;-)

    Please provide a little more info on exactly what the goal here is. When you say "delete a file from a database" - what exactly do you mean by that?

    -- vek --
Re: Deleting Old Files in a DB.
by EdwardG (Vicar) on Oct 09, 2003 at 11:00 UTC