in reply to Reading from ls-lrt (was: Reading)
Additionally, if you want the most recent files, instead of using -r and getting the last five files, you should use the default sort order and get the first five files. Thus:
my @files = (`ls -1t`)[0..4]; chomp(@files);
However, it might be preferable to do all this in Perl, and avoid spawning a shell and relying on the behavior of ls.
opendir(DIR, '.') or die "Can't opendir '.': $!\n"; my @files = readdir(DIR); closedir(DIR); @files = map $_->[0], sort { $b->[1] <=> $a->[1] } map { /^\./ ? () : [ $_, (lstat $_)[9] ] } @files; @files = @files[0..4];
|
|---|