Sorting

E

ExecMan

Hi,

I'm looking to read a directory to get a list of files in Descending
sorted order by timestamp. I've gotten this so far, but it is in
ascending. Can anyone help with the descending part?

my $dir = '/home/logfiles';

opendir my $DH, $dir or die "Cannot opendir '$dir' $!";

my @sorted_files =
map $_->[1],
sort { $a->[0] <=> $b->[0] }
map -f "$dir/$_" ? [ ( stat _ )[9], $_ ] : (),
readdir $DH;

for ($i=0; $i<20; $i++) {
print "FILE: $sorted_files[$i]\n";
}


Thank a bunch!
 
T

Tim McDaniel

I'm looking to read a directory to get a list of files in Descending
sorted order by timestamp.

In Linux or other UNIX-like systems, you can use the command "ls -t".
 
J

Jürgen Exner

ExecMan said:
I'm looking to read a directory to get a list of files in Descending
sorted order by timestamp. I've gotten this so far, but it is in
ascending. Can anyone help with the descending part?

If nothing else this hack will work:
perldoc -f reverse

:)

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top