[PLUG] Grab the most recent file in perl?

Stafford A. Rau srau at rauhaus.org
Fri Feb 14 09:42:02 UTC 2003


* Randal L. Schwartz <merlyn at stonehenge.com> [030214 06:31]:
> So, you either use a Schwartzian Transform, effectively turning
> Perl into a "fetch the mtime once" mode just like "ls -t", or
> you use a high-water-mark algorithm:
> 
>     my @files = <some*glob*here>;
>     my $oldest = shift @files;
>     my $age_of_oldest = -M $oldest;
>     for (@files) {
>       my $age = -M $_;
>       if ($age > $age_of_oldest) {
>         $oldest = $_;
>         $age_of_oldest = $age;
>       }
>     }

Exactly what I was hoping to find.

Thanks, I was hoping to get the Schwartzian perspective for this.

--Stafford




More information about the PLUG mailing list