in reply to Sort files descending by date
use strict; use warnings; my $SOME_DIR = '/home/scrat/scratchpad'; my $PATTERN = qr{ \A \w+ (\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d_\d\d\d) [\.\w]* \.xml \z }xms; opendir( DIR, $SOME_DIR ) || die "can't opendir $SOME_DIR: $!"; my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { ($_ =~ $PATTERN) && [$_, $1] } grep { ($_ =~ $PATTERN) && -f "$SOME_DIR/$_"} readdir( DIR ) ; closedir DIR; printf "%s\n", join "\n", @sorted;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort files descending by date
by johngg (Canon) on Jun 19, 2007 at 09:50 UTC | |
by fenLisesi (Priest) on Jun 19, 2007 at 09:53 UTC | |
by johngg (Canon) on Jun 19, 2007 at 10:08 UTC |