title: Open a directory and sort files by date created
body: <p>I need to open directories and sort the files by the time they were created. I can find some discussion, using tags for Perl, sorting, and files, on sorting files based on date of modification. I assume this is a more common need than sorting by date of creation. I use Perl. There is some previous postings on sorting by creation date in other languages other than Perl, such as php or java.</p>
  
  <p>For example, I need to do the following:</p>
  
  <pre><code>opendir(DIR, $ARGV[0]);                             
  my @files = "sort-by-date-created" (readdir(DIR)); 
  closedir(DIR);
  
  do things with @files...
  </code></pre>
  
  <p>The CPAN has a page on the sort command, but it's not very accessible to me, and I don't find the words "date" or "creation" on the page.</p>
  
  <p>In response to an edit, I should say I use Mac, OS 10.7. I know that in the Finder, there is a sort by creation date option, so there must be some kind of indication for date of creation somehow attached to files in this system. </p>
  
  <p>In response to an answer, here is another version of the script that attempts to sort the files:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict; use warnings;
  
  use File::stat; # helps with sorting files by ctime, the inode date that hopefully can serve as creation date
  
  my $usage = "usage: enter name of directory to be scanned for SNP containing lines\n";
  die $usage unless @ARGV == 1;
  
  opendir(DIR, $ARGV[0]);                             #open directory for getting file list
  #my @files = (readdir(DIR));
  my @file_list = grep ! /^\./, readdir DIR; 
  closedir(DIR);  
  
  print scalar @file_list."\n";
  
  for my $file (sort {
          my $a_stat = stat($a);
          my $b_stat = stat($b);
          $a_stat-&gt;mtime &lt;=&gt; $b_stat-&gt;mtime;
      }  @file_list ) {
      say "$file";
  }
  </code></pre>