Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting a directory by last modified date

Posted on 2000-02-15
5
Medium Priority
?
178 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 85

Expert Comment

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

Accepted Solution

by:
amitpagarwal earned 280 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 85

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

916 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