Well it's 3:00 AM on Monday for me but I see a recent post so here is some code that ought to give you a lot of ideas. It sorts by atime and I think ought to have enough commented out print statements to help understand what is going on.

PS: I really recommend the "use strict;" line in there. I put it in every perl program I write. See strict for more info.

Update: added @lowest_ten_times to show how to get the lowest 10 times.

#!/usr/bin/perl -w use strict; use Data::Dumper; my $directory = "/home/frink/code/perl/z/"; opendir DIR, $directory; my @file_names = readdir DIR; closedir DIR; # remove "." and ".." @file_names = grep {!/^\.$/} @file_names; @file_names = grep {!/^\.\.$/} @file_names; # add the full path name back on (used by "stat()" below.) @file_names = map {$_ = $directory . $_} @file_names; # print "file_names: " . Dumper(\@file_names); my %times_to_names; foreach my $name (@file_names) { my $atime = (stat($name))[8]; $times_to_names{$atime} = $name; # print "file: $name\t"; # print "atime: $atime\t"; # print "\n"; } # print "times_to_names: " . Dumper(\%times_to_names); my @times_sorted = sort(keys(%times_to_names)); # print "times_sorted: " . Dumper(\@times_sorted); foreach my $time (@times_sorted) { print $time . "\t" . $times_to_names{$time} . "\n"; } my @lowest_ten_times = @times_sorted[0..9]; # print "lowest_ten_times: " . Dumper(\@lowest_ten_times);

In reply to Re: sorting a directory by superfrink
in thread sorting a directory by bioskope

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.