Solved

Sorting a directory by last modified date

Posted on 2000-02-15
5
164 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now