use strict;
use warnings;
use 5.010;
my @filelist = glob('c:\data\perl\bin\*.bat');
{local $,="\n"; say 'Unsorted', @filelist;}
say;
my @sorted = sort by_last_mod @filelist;
{local $,="\n"; say 'Sorted', @sorted};
sub by_last_mod {
my $adate = ( stat($a) )[9];
my $bdate = ( stat($b) )[9];
return $adate <=> $bdate;
}
Output:Unsorted
c:\data\perl\bin\ap-iis-config.bat
c:\data\perl\bin\ap-update-html.bat
c:\data\perl\bin\ap-user-guide.bat
c:\data\perl\bin\c2ph.bat
(...)
Sorted
c:\data\perl\bin\latexmk.bat
c:\data\perl\bin\dprofpp.bat
c:\data\perl\bin\exetype.bat
c:\data\perl\bin\perlglob.bat
(...)
Maybe your initial array was already sorted?
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|