in reply to Re: Deleting files based on date
in thread Deleting files based on date

I don't know why, but I find -M and friends confusing, because they work the 'wrong' way for my brane, by making older files have higher values, whereas stat and friends use epoch time and newer files have higher values. So I'd use stat like below. There's a little more code, but it's easier for me to read:
unlink grep { (stat($_))[9] < time - ($days * 86400) } @files;
where 86400 is the number of seconds in a day, so we unlink all files from the @files array where their modification time earlier than $days days old.

Replies are listed 'Best First'.
Re: Re: Re: Deleting files based on date
by liz (Monsignor) on Oct 20, 2003 at 08:55 UTC
    ...I find -M and friends confusing, because they work the 'wrong' way for my brane...

    I agree, but for a different reason: the fact that calculations are done from script startup time can lead to unexpected results for long-running scripts, or when running under mod_perl.

    That's why I personally prefer to use stat() as well: changing $^T is too much "action at a distance" to me.

    On the other hand, being able to recognize 86400 as a synonym for a day, is a typicial sysadmin deformity to me ;-)

    Liz