CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Need to Pick the lastest written file in a directory.

 



C_PRASANNA
Novice

May 6, 2014, 5:56 AM

Post #1 of 3 (10224 views)
Need to Pick the lastest written file in a directory. Can't Post

Guys,

I need to pick a latest written file in a directory.

How do i pick the latest written file in a array from Newest to Oldest order ?

Any Idea ????

Regards -Prasanna


Chris Charley
User

May 6, 2014, 8:54 AM

Post #2 of 3 (10159 views)
Re: [C_PRASANNA] Need to Pick the lastest written file in a directory. [In reply to] Can't Post

Using 'reduce' from List::Util.


Code
#!/usr/bin/perl 
use strict;
use warnings;
use List::Util 'reduce';

my $dir = ".";
my $newest = reduce {-M $a < -M $b ? $a : $b} glob "$dir/*.*";



Laurent_R
Veteran / Moderator

May 6, 2014, 9:58 AM

Post #3 of 3 (10136 views)
Re: [Chris Charley] Need to Pick the lastest written file in a directory. [In reply to] Can't Post

Nice idea to use reduce for this.

Cool

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives