title: How can I read the files in a directory in sorted order?
body: <p>When I read a directory in Perl with <code>opendir</code>, <code>readdir</code>, and <code>closedir</code>, the <code>readdir</code> function doesn't seem to read the files in any specific order (that I can tell).</p>
  
  <p>I am reading a directory that has subdirectories named by epoch timestamp:</p>
  
  <pre><code>1224161460
  1228324260
  1229698140
  </code></pre>
  
  <p>I want to read in these directories in numerical order, which would put the oldest directories first.</p>
  
  <p>When I use <code>readdir</code>, the first one it reads is 1228324260, which is the middle one.  I know I could put the directory contents in an array and sort the array, but is there an option I can pass to <code>readdir</code> to read in sorted order?  Or maybe a more elegant way of accomplishing this than pushing everything into array and sorting the array?  There are probably modules out there to do this too, but it is difficult to get modules installed in our environment, so unless it is a built-in module I'd prefer to not use modules...</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong>
  As requested, I am posting the code that I am using:</p>
  
  <pre><code>opendir( my $data_dh, $data_dir ) or die "Cannot open $data_dir\n";
  while ( my $name = readdir($data_dh) ) {
      next if ( $name eq '.' or $name eq '..' );
      my $full_path = "${data_dir}/${name}";
      next unless ( -d $full_path );
      process_dir($full_path);
  }
  closedir($data_dh);
  </code></pre>