rmacmich
asked on
Sorting a directory by last modified date
In UNIX, using Perl, what would be the code to get a directory listing (with no traversing subdirectories) of files with a particular extension, sorted by last date modified and stored in an array?
Thanks!
Thanks!
@array = sort {-M $a <=> -M $b} <*.ext>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ozo,
that's supposed to be
@array = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, -M] }
<*.ext>;
you posted the schwartzian transform to one of my comments a long time ago.
Tobias
that's supposed to be
@array = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, -M] }
<*.ext>;
you posted the schwartzian transform to one of my comments a long time ago.
Tobias
#or using a generic Schwartzian Transform:
sub ST(&@){
my $metric=shift;
map {$_->[0]}
sort {$a->[1] cmp $b->[1]}
map {[$_,&{$metric}]} @_
}
@array = ST {pack'N',(stat)[9]} <*.bak>;
sub ST(&@){
my $metric=shift;
map {$_->[0]}
sort {$a->[1] cmp $b->[1]}
map {[$_,&{$metric}]} @_
}
@array = ST {pack'N',(stat)[9]} <*.bak>;
ozo, I have posted a new question for you in this topic area.
darinw
Customer Service
darinw
Customer Service