Sorting

Discussion in 'Perl Misc' started by ExecMan, May 12, 2012.

  1. ExecMan

    ExecMan Guest

    Hi,

    I'm looking to read a directory to get a list of files in Descending
    sorted order by timestamp. I've gotten this so far, but it is in
    ascending. Can anyone help with the descending part?

    my $dir = '/home/logfiles';

    opendir my $DH, $dir or die "Cannot opendir '$dir' $!";

    my @sorted_files =
    map $_->[1],
    sort { $a->[0] <=> $b->[0] }
    map -f "$dir/$_" ? [ ( stat _ )[9], $_ ] : (),
    readdir $DH;

    for ($i=0; $i<20; $i++) {
    print "FILE: $sorted_files[$i]\n";
    }


    Thank a bunch!
     
    ExecMan, May 12, 2012
    #1
    1. Advertising

  2. ExecMan

    ntua Guest

    sort { $b->[0] <=> $a->[0] }
     
    ntua, May 14, 2012
    #2
    1. Advertising

  3. ExecMan

    Tim McDaniel Guest

    In article
    <>,
    ExecMan <> wrote:
    >I'm looking to read a directory to get a list of files in Descending
    >sorted order by timestamp.


    In Linux or other UNIX-like systems, you can use the command "ls -t".

    --
    Tim McDaniel,
     
    Tim McDaniel, May 14, 2012
    #3
  4. ExecMan <> wrote:
    >I'm looking to read a directory to get a list of files in Descending
    >sorted order by timestamp. I've gotten this so far, but it is in
    >ascending. Can anyone help with the descending part?


    If nothing else this hack will work:
    perldoc -f reverse

    :)

    jue
     
    Jürgen Exner, May 15, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ashish

    sorting techniques

    Ashish, Nov 15, 2003, in forum: VHDL
    Replies:
    0
    Views:
    561
    Ashish
    Nov 15, 2003
  2. Replies:
    2
    Views:
    1,459
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    395
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    483
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    166
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page