Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do you write a perl script to calculate the age of a file

by ezekiel (Pilgrim)
on Jun 19, 2001 at 03:58 UTC ( [id://89524]=note: print w/replies, xml ) Need Help??


in reply to How do you write a perl script to calculate the age of a file

I think the -M operator gives you the number of days since a file was last modified. Hence:
if (-M $filename > 2) { unlink ($filename); }
should work if you want to delete files that were last modified over 2 days ago. -A and -C do the same thing based on last access time and last inode change.

Replies are listed 'Best First'.
Re: Re: How do you write a perl script to calculate the age of a file
by VSarkiss (Monsignor) on Jun 19, 2001 at 07:32 UTC
    Ah, when will the golf urge pass? You could do: unlink $filename if -M $filename > 2; saving yourself two parentheses and two squiggly braces. ;-)

    It even reads exactly as the questioner proposed: "delete the file if it is more than two days old".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://89524]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found