Joseph Alotta wrote:
> On May 13, 2004, at 11:12 PM, Matt Doughty wrote:
> 
> 
>>here is my little bit for making a really short solution.
>>
>>--Matt
>>
>>#!perl
>>my $dir = shift() || ".";
>>opendir(DIR, $dir);
>>print for(map { $_ . "\n" } sort { (stat($b))[9] <=> (stat($a))[9] } 
>>grep { !/^.{1,2}$/ } readdir DIR );

\. needed here instead of .

> 
> 
> All these solutions are still too verbose and self-documenting.  Can 
> someone write something a little shorter, maybe a one-liner?

"Does it have to fit in 80 columns?" :-)

opendir(DIR, shift || ".") && print map { "$_->[1]\n" } sort { $a->[0]
<=> $b->[0] || $a->[1] cmp $b->[1] } map { [ (stat($_))[9], $_ ] } grep
{ !/^\.{1,2}$/ } readdir(DIR)

Note the added cmp test in case timestamps compare equal.

Pity that opendir() doesn't return a dirhandle.

> Joe.
> 
> 

Reply via email to