Razorwyre
08-15-2002, 04:34 PM
Here's the deal: I've got a flat-file (text file) database that stores a simple list of items, as such:
Category|Title|Description|Date
(Date is in the format: YYYYMMDD -- so it should be easy to sort numerically)
Each line in the file is a new entry. What I'm trying to do is write a function that will read all the lines from the file, sort them by date with the newest at the top, and write back a new file with everything in a nice, sorted order.
I can read the file and use split() to get each of the four pieces of data from each row. That's easy enough. My difficulty is in figuring out how best to do the sort. If this were a mysql db, it'd be easy to just sort the data with mysql before pulling it out... but since it's a text file db, it requires more work... (I was thinking of trying a multiarray and using the multisort array function, but I'm not sure even how to go about that or if it's the easiest solution...)
anyone able to help?
thanks in advance!
-raz
Category|Title|Description|Date
(Date is in the format: YYYYMMDD -- so it should be easy to sort numerically)
Each line in the file is a new entry. What I'm trying to do is write a function that will read all the lines from the file, sort them by date with the newest at the top, and write back a new file with everything in a nice, sorted order.
I can read the file and use split() to get each of the four pieces of data from each row. That's easy enough. My difficulty is in figuring out how best to do the sort. If this were a mysql db, it'd be easy to just sort the data with mysql before pulling it out... but since it's a text file db, it requires more work... (I was thinking of trying a multiarray and using the multisort array function, but I'm not sure even how to go about that or if it's the easiest solution...)
anyone able to help?
thanks in advance!
-raz