in reply to Sorting an array by dates in a field...

I think what you explained is not, in fact, what you have. You describe a file that has three bits of information in it: one date, one id, and one title. You assign this to an array such that element zero is $date, one is $id, and two is $title.

This is clearly not the case, or there would be no sorting to do! :-) Could you post your code (remember to surround your code with <code> tags) and some sample data?

Replies are listed 'Best First'.
Re: Re: Sorting an array by dates in a field...
by Speedfreak (Sexton) on Jul 07, 2001 at 03:25 UTC

    O.K, sorry! Its 1:22am here and I'm not thinking straight! %P

    I havent got the data yet so at the moment i'm just "simulating" 3 lines from the file being in the array:

    #!/usr/bin/perl my @data; push @data, [ split (/\|/,"2001-07-07|12345|This is a test 1") ]; push @data, [ split (/\|/,"2001-07-08|23456|This is a test 2") ]; push @data, [ split (/\|/,"2001-07-06|34567|This is a test 3") ]; print $data[0][0];

    So as you can see, at the end it prints "2001-07-07" which is the "first row, first column" of the array.

    What I want to do is that this array and sort it by date in descending order using the date field.

    By the way - what IS the proper term for these sorts of arrays in Perl and how do you refer to the "rows and columns" I always use? *S* I mean, what is it when you know how many "columns" you have but the number of rows (say its being read from a file) is variable?

    - Jed