doubledecker has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I'm trying to find the latest file created or modified by time in a directory and using the following code
opendir(my $DH, $DIR) or die "Error opening $DIR: $!"; my @files = map { [ stat "$DIR/$_", $_ ] } grep(! /^\.\.?$/, readdir($ +DH)); closedir($DH); sub rev_by_date { $b->[9] <=> $a->[9] } my @sorted_files = sort rev_by_date @files; my @newest = @{$sorted_files[0]}; my $name = pop(@newest);
But the problem is that in my perl script, I am using File::stat module and inturn 'stat' used inside 'map' is referring to File::stat module but not core function. This results in getting a wrong file name. How can I resolve this issue. any help is appreciated.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: find the latest created file in a directory
by Tux (Canon) on Apr 24, 2013 at 13:57 UTC | |
by Krambambuli (Curate) on Apr 24, 2013 at 14:59 UTC | |
by Tux (Canon) on Apr 24, 2013 at 15:11 UTC | |
by Krambambuli (Curate) on Apr 24, 2013 at 15:33 UTC | |
Re: find the latest created file in a directory
by johngg (Canon) on Apr 24, 2013 at 20:45 UTC | |
Re: find the latest created file in a directory
by Anonymous Monk on Apr 24, 2013 at 13:44 UTC | |
Re: find the latest created file in a directory
by pvaldes (Chaplain) on Apr 24, 2013 at 14:18 UTC | |
Re: find the latest created file in a directory
by Krambambuli (Curate) on Apr 24, 2013 at 14:17 UTC | |
Re: find the latest created file in a directory
by sureshepuri (Initiate) on Apr 25, 2013 at 06:58 UTC |
Back to
Seekers of Perl Wisdom