in reply to Re: Sorted by date file not working?!
in thread Sorted by date file not working?!

Yes I am using readdir.

I checked that @filelist is correct (really contains the file names), and that it is not already sorted (LOL);

After the sort, I check @sorted and see that it is exactly the same then @filelist. No sort at all was done.

I also used File::Stat, same result :(

  • Comment on Re^2: Sorted by date file not working?!

Replies are listed 'Best First'.
Re^3: Sorted by date file not working?!
by jwkrahn (Abbot) on Mar 04, 2010 at 15:24 UTC

    If you are using readdir then you have to prepend the directory name to the file name when you do the stat, for example:

    opendir DH, $dir or die "Cannot opendir '$dir' $!"; my @filelist = readdir DH; my @sorted = sort by_last_mod @filelist; sub by_last_mod { my $adate = ( stat "$dir/$a" )[ 9 ]; my $bdate = ( stat "$dir/$b" )[ 9 ]; return $adate <=> $bdate; }