Solved

Sorting a directory by last modified date

Posted on 2000-02-15
5
168 Views
Last Modified: 2010-03-05
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!
0
Comment
Question by:rmacmich
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2525062
@array = sort {-M $a <=> -M $b} <*.ext>
0
 
LVL 5

Accepted Solution

by:
amitpagarwal earned 70 total points
ID: 2526495

@array = `ls -1t *.extn`

- amit
0
 
LVL 5

Expert Comment

by:thoellri
ID: 2527568
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
0
 
LVL 84

Expert Comment

by:ozo
ID: 2528969
#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>;
0
 
LVL 3

Expert Comment

by:darinw
ID: 2529869
ozo, I have posted a new question for you in this topic area.

darinw
Customer Service
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question