http://www.perlmonks.org?node_id=400255

Nitrox has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that needs to determine the oldest file in a particular directory and I'm concerned about the efficiency of my current solution. (This runs every 60 seconds, which is why I'm concerned with optimization). Here's an example snippet:

my $dir = "."; my $file = (sort{(stat $a)[10] <=> (stat $b)[10]}glob "$dir/*.pl")[0];

This script runs across multiple platforms (Win32, Solaris, Linux and AIX) so limits me from some perhaps "easier" solutions.

Another important piece of info is that the directory is relatively small and has no more than 10 files at any given time, so I wasn't concered about the numerous stat calls.

So is my current solution acceptable, and I'm trying to micro-optimize, or does anyone see a glaring performance issue?

Thanks in advance for feedback!

-Nitrox