Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!
I have a report that prints a list of files showing its age using:
my $datetime = ctime(stat("files")->mtime);
But this list is not in descending or ascending order, the dates are all over the place and I would like to do that with this list that looks like this:
file7 - From: Sun Jan 30 08:20:52 2011 file4 - From: Tue Feb 1 19:07:46 2011 file6 - From: Sun Jan 30 09:09:43 2011 file0 - From: Fri Dec 21 07:25:10 2010 file2 - From: Sat Jan 22 18:16:46 2011 filef - From: Wed Feb 2 16:12:59 2011 file13 - From: Mon Jan 31 13:46:37 2011 file6ff - From: Tue Feb 1 07:27:06 2011 file6 - From: Wed Feb 2 07:28:23 2010 filee - From: Sat Jan 22 11:27:49 2011 filec - From: Sat Jan 22 16:52:42 2011 file2b - From: Wed Feb 2 14:28:56 2011
Has anyone here done anything like that? Thanks for looking!

Replies are listed 'Best First'.
Re: Sort Dates Help!
by ikegami (Patriarch) on Feb 08, 2011 at 05:34 UTC
    my @files_info; foreach (@files) { push @files_info, [ $_, stat($_)->mtime() ]; } @files_info = sort { $a->[1] <=> $b->[1] || $a->[0] cmp $b->[0] } @files_info; foreach (@files_info) { print(ctime($_->[0]) . " - From: $_->[1]\n"); }