#!/usr/bin/perl $dir = shift || '.'; my $latest = (sort {$b->{mtime} <=> $a->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; print $latest->{file}, "\n"; #Using map allows -M to be performed on each file only once #per sort iteration. #once will save a lot of CPU time.
In reply to Re: Finding Newest File in Perl
by zentara
in thread Finding Newest File in Perl
by aatlamaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |