Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: find the latest created file in a directory

by johngg (Abbot)
on Apr 24, 2013 at 20:45 UTC ( #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


Comment on Re: find the latest created file in a directory
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-09-01 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (9 votes), past polls