Hi Monks!
I want to build a subroutine which returns the latest modified file in an array of files (could be regular file, link or directory).
The area is given in
$base_dir variable and the filenames list hash ref is given in
$filenames_href (The keys are the number and the values are just "1").
The initial code:
sub test {
my ($base_dir,$filenames_href) = @_;
foreach my $filename (keys(%{$filenames_href})) {
my $file_path = catfile($base_dir,$filename); # Could be file,
+ dir, link, ...
# TODO: Check if the $file_path is the latest I seen ?
}
return $latest_modified_file;
}
For example:
ls -la .
-rw-r----- 1 user group 33659 Nov 3 14:49 a
drwxr-x--- 3 user group 4096 May 3 2021 b
drwxr-x--- 3 user group 4096 Dec 8 16:18 c
-rwxr-x--x 1 user group 67 Apr 5 2021 e
drwxr-x--- 4 user group 4096 Nov 1 15:29 f
-rw-r----- 1 user group 798 Nov 15 17:00 g
In that case the sub should return
c because it was modified latest. Is there a standard way to do it?