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".