heres something i came up with. please dont laugh at me cos I am really new to all this. my objective is to get 100 files from a directory having the oldest access times and then delete them(something like a cache)
sub make_space {
my $folder_name = $_[0];
opendir DIR_HANDLE, ".$folder_name";
my @filelist = readdir DIR_HANDLE;
close DIR_HANDLE;
foreach $filename(@filelist) {
$st = stat($ilename)
$actime = st->$atime
}
#custom sort routine to sort the filelist according to their last acce
+ssed date
@sorted_list = sort { ($actime{$a}) >
($actime{$b})
} @filelist;
#deleting 1st 100 entries in the sorted array
for($i =0; $i <=99 ;$i=$i+1)
{
unlink($sorted_list[i]);
}
}
|