http://qs321.pair.com?node_id=1030401

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.