in reply to Appending date to filename for Archiving

foreach ( glob '*' ) { my $file_date = POSIX::strftime '%Y%m%d', localtime( ( stat )[ 9 ] + ); my $age = -M _; if ( $age >= 1 && $age < 2 ) { #rename Log File to .log.yyyymmdd rename $_, $_ . $file_date; } elsif ( $age > 14 ) { unlink $_; }

Replies are listed 'Best First'.
Re^2: Appending date to filename for Archiving
by viperl (Initiate) on Jun 29, 2009 at 13:38 UTC
    Thanks for that jwkrahn. Can you explain taht statement. I want to get an understanding of what this sattement does
    my $file_date = POSIX::strftime '%Y%m%d', localtime( ( stat )[ 9 ]+ );

      That creates a string of the year, month, and day of the mtime of the current file name in $_.   Since you are testing the mtime via the -M operator, that date should be the same as yesterdays date, however you could calculate it yourself if that is what you require.