Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Deleting Old Files in a DB.

by Anonymous Monk
on Oct 09, 2003 at 00:15 UTC ( #297773=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://297773]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-03-04 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (97 votes). Check out past polls.

    Notices?