<?xml version="1.0" encoding="windows-1252"?>
<node id="400255" title="Finding oldest file in directory" created="2004-10-18 14:11:38" updated="2005-08-12 16:23:00">
<type id="115">
perlquestion</type>
<author id="171047">
Nitrox</author>
<data>
<field name="doctext">
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:
&lt;p&gt;
&lt;code&gt;
my $dir = ".";
my $file = (sort{(stat $a)[10] &lt;=&gt; (stat $b)[10]}glob "$dir/*.pl")[0];
&lt;/code&gt;
&lt;p&gt;
This script runs across multiple platforms (Win32, Solaris, Linux and AIX) so limits me from some perhaps "easier" solutions.
&lt;p&gt;
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 &lt;code&gt;stat&lt;/code&gt; calls.
&lt;p&gt;
So is my current solution acceptable, and I'm trying to micro-optimize, or does anyone see a glaring performance issue?
&lt;p&gt;
Thanks in advance for feedback!
&lt;p&gt;
-Nitrox</field>
</data>
</node>
