ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
For example: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; }
In that case the sub should return c because it was modified latest. Is there a standard way to do it?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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting latest modified file in a directory
by hippo (Archbishop) on Jan 10, 2022 at 16:24 UTC | |
|
Re: Getting latest modified file in a directory
by tybalt89 (Monsignor) on Jan 10, 2022 at 21:08 UTC | |
|
Re: Getting latest modified file in a directory
by Fletch (Bishop) on Jan 10, 2022 at 18:29 UTC | |
|
Re: Getting latest modified file in a directory -- oneliner
by Discipulus (Canon) on Jan 11, 2022 at 09:34 UTC |