sort directory help

Discussion in 'Perl Misc' started by Nathan, Jan 3, 2005.

  1. Nathan

    Nathan Guest

    http://search.cpan.org/~muir/Time-modules-2003.1126/lib/Time/ParseDate.pm

    might help you, or you could parse it yourself.

    --Nathan

    "Jake Wiley" <> wrote in news:1104788305.272941.63060
    @c13g2000cwb.googlegroups.com:

    > I need to sort a directory which is all fine BUT my directory names are
    > all in date formats like Nov 18 2004, Dec 23, 2005 etc.. The simple
    > sort works BUT like this:
    > Aug 5 2004
    > Dec 1 2004
    > Dec 8 2004
    > Jan 2 2005
    > Nov 7 2004
    >
    > I want to get the folders in chronological order. It's for a backup
    > program and I want to be able to delete the oldest folder after a
    > couple of weeks. Could somebody please point me in the right direction
    > or perhaps a module that does this. Thanks
    >
    >
     
    Nathan, Jan 3, 2005
    #1
    1. Advertising

  2. Nathan

    Jake Wiley Guest

    I need to sort a directory which is all fine BUT my directory names are
    all in date formats like Nov 18 2004, Dec 23, 2005 etc.. The simple
    sort works BUT like this:
    Aug 5 2004
    Dec 1 2004
    Dec 8 2004
    Jan 2 2005
    Nov 7 2004

    I want to get the folders in chronological order. It's for a backup
    program and I want to be able to delete the oldest folder after a
    couple of weeks. Could somebody please point me in the right direction
    or perhaps a module that does this. Thanks
     
    Jake Wiley, Jan 3, 2005
    #2
    1. Advertising

  3. Nathan

    Jake Wiley Guest

    Thanks for the info Nathan

    I tried your sample Jim Gibson and It looks like it's trying to work
    but only after several of these messages:
    Use of uninitialized value in numeric comparison (<=>) at blah blah
    blah line 14
    which was this line :

    map{ $_->[0] }

    After that the ouput was Aug 5 2004 Nov 7 2004 etc in chronological
    order. Thats what I needed.. :)

    Here is my modified piece.
    opendir(DIRHANDLE, "E:\\Backup") or die "couldn't open E:\\Backup :
    $!";
    my @dates = readdir(DIRHANDLE);
    my @sorted =
    map{ $_->[0] }
    sort { $a->[1] <=> $b->[1] }
    map { [$_, parsedate($_)] } @dates;
    print @sorted;

    Why the error message about "Use of uninitialized value in numeric
    comparison (<=>)"
     
    Jake Wiley, Jan 5, 2005
    #3
  4. Jake Wiley <> wrote:

    > my @sorted =
    > map{ $_->[0] }
    > sort { $a->[1] <=> $b->[1] }
    > map { [$_, parsedate($_)] } @dates;


    > Why the error message about "Use of uninitialized value in numeric
    > comparison (<=>)"



    Because parsedate() returned undef.

    Consult the function's documentation to see why it
    might do that.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 5, 2005
    #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. nobody
    Replies:
    0
    Views:
    568
    nobody
    Jun 1, 2004
  2. JerryJ
    Replies:
    11
    Views:
    1,432
    Dave Moore
    Apr 28, 2004
  3. John Black
    Replies:
    6
    Views:
    2,113
    John Harrison
    May 28, 2004
  4. Navin
    Replies:
    1
    Views:
    766
    Ken Schaefer
    Sep 9, 2003
  5. GIMME
    Replies:
    5
    Views:
    201
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page