in reply to Getting a list of files in a directory sorted by date

I'm not sure how expensive pulling the date for a file is, but assuming it's reasonably exensive and you have a lot of files, then a Schwartzian Transform is a natural way to go.

opendir DIR, $logdir or die "Cannot open $logdir: $!"; my @cfiles = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ -M $_, $_ ] } grep { /\w/ } readdir DIR;

Update: Fixed the typo that slloyd and philcrow pointed out (/w/ should have been /\w/).

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^2: Getting a list of files in a directory sorted by date
by philcrow (Priest) on Apr 07, 2006 at 17:54 UTC
    The grep expression here looks funny. It seems to say the file must contain a w. Perhaps you meant:
    grep { /\w/ }
    Phil
Re^2: Getting a list of files in a directory sorted by date
by slloyd (Hermit) on Apr 07, 2006 at 17:04 UTC
    Your code example does not return any files.

    -------------------------------
    Perl - Regularly Expression yourlself
    http://www.basgetti.com

        Yep must have been the \w

        -------------------------------
        Perl - Regularly Expression yourlself
        http://www.basgetti.com