in reply to sorting a directory

In future, before asking a question, I suggest you use the Perl Monks Super Search. This question was asked and answered a while back: Sorting based on filesize.

Replies are listed 'Best First'.
thanx a lot guys
by bioskope (Initiate) on Dec 27, 2004 at 04:25 UTC
    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]); } }
      Oh well if you want to delete the 100 oldest files in a directory and you are using a unix-like system them the following might work for you.
      ls -1rt /home/frink/code/perl/z/ | head -100 | xargs rm