in reply to date sorted files into an array
If you want something that will work on systems that don't support "ls -t", then I think you should start with a hash, keyed by file name, with file ages as the values -- it involves doing a stat on each file just once (rather than multiple times within a sort block, as suggested in ccn's reply). Something like this:
But if you're just running you code "in shop" (as opposed to including it in a package for open distribution), using "ls" with back-ticks is fine.my %files; opendir( D, "." ); # or some specific path? -f and $files{$_} = -M _ for ( readdir D ); closedir D; my @newest_first = sort { $files{$a} <=> $files{$b} } keys %files;
|
|---|