Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: find "x" quantity newest files in a dir

by mr.nick (Chaplain)
on Jun 27, 2001 at 19:55 UTC ( [id://91952]=note: print w/replies, xml ) Need Help??


in reply to find "x" quantity newest files in a dir

I'll add my belated $0.02 here ... if you want to grab the 10 most recent files in a directory, try something like:
my $dir="."; my @files=(map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ -M $_, $_ ] } glob("$dir/*"))[0..9];
Then you can simply do whatever operation you want on @files. If you want all the files EXCEPT the newest ten, you can invert the sort logic and play with splice ala:
my $dir="."; my @files=(map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ -M $_, $_ ] } glob("$dir/*")); splice (@files,-10);

mr.nick ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://91952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found