I'm looking for a quick way to read lines of data from a text file into
memory. Each line will contain e.g. a book entry: -
id,name,price,category,author,description
I could have over 20000 of these lines, and I'd like a function that
reads in the list of books grabbing only the id and name fields. Then
I'd like another function that when passed an id will grab all the
details from that entry.
So my dilemma is how to read in this information as efficiently as
possible. So far the best I can think of is a random access file with
each field (and therefore each record) taking up X bytes. I can then
use a file pointer and get to a specific line very quickly. The two
reasons I don't want to do this is (a) I have to give limits on field
lengths, and (b) I can't really edit the entries in the file by hand
(which would be desirable).
Anyone have any ideas on another way I can accomplish an efficient data
retrieval like this from a file?
Many thanks,
James