in reply to Finding Newest File in Perl
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding Newest File in Perl
by aatlamaz (Novice) on Dec 07, 2004 at 14:39 UTC |