http://www.perlmonks.org?node_id=492359


in reply to Temp file strategy

I use the following to keep webserver-generated links (and files) valid for three hours:
#[snip]# # Finally, remove old spreadsheets from temporary directory opendir(TMPD, $tmpdir) or die "No tmp Directory! $! \n"; while (my $f = readdir(TMPD)) { if ($f =~ /\.xls$/) { if ((-A "$tmpdir/$f") > 0.125) # if file is older than 3 hours, de +lete it { system('rm', '-f', "$tmpdir/$f") && die "Can't remove $f: $!\n"; } } } closedir(TMPD); #[snip]#
The files and the directory need to be writable by the webserver, but since earlier incarnations of the same page create them, that is not a problem.