in reply to Finding Newest File in Perl

Modify for either newest or latest:
#!/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.

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Finding Newest File in Perl
by aatlamaz (Novice) on Dec 07, 2004 at 14:39 UTC
    Thanks Guys, Thanks Zentara, it works great now!...