in reply to Re: need helping sorting
in thread need helping sorting

This will work, but it's not so efficient (you end up redoing the stat calls on each file in that sort). So what you might do is grab the files and their modification times, storing that in a hash (filename => modtime) then sort on modtime, e.g. :

opendir FILES, $dirname or die "Can't open $dirname:$!\n"; chdir $dirname; #to make sure we're in the right directory! # build the hash, in one line! YES! IF YOU ACT NOW, ALL THIS AND MOR +E # CAN BE YOURS! ... </perl_salesman> my %files = map {$_ => -M $_} grep { !/^\.{1,2}$/ } readdir FILES; closedir FILES; foreach my $file ( sort { $files{$a} <=> $files{$b} } keys %files) { printf("file %s was last modified %.2f days ago", $file, $files{$f +ile}); }

HTH

Philosophy can be made out of anything. Or less -- Jerry A. Fodor