Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: find the latest created file in a directory

by johngg (Canon)
on Apr 24, 2013 at 20:45 UTC ( [id://1030524]=note: print w/replies, xml ) Need Help??


in reply to find the latest created file in a directory

Using &List::Util::reduce, can save having to sort.

$ perl -MList::Util=reduce -Mstrict -Mwarnings -E ' my $newest = reduce { $a->[ 1 ] > $b->[ 1 ] ? $a : $b } do { opendir my $dotDH, q{.} or die qq{opendir: .: $!\n}; map { [ $_, ( stat $_ )[ 9 ] ] } grep { -f and not -l } readdir $dotDH; }; say qq{Newest file - $newest->[ 0 ]};' Newest file - spw1029421 $

And that really is the newest file in the directory :-)

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found