You've discovered why advanced data structures are necessary. (For reference, see perlref and perldsc.)
No matter how you store your data, you need to keep track of some additional information, namely, the children of the current message. You could set up something like this:
my %message = (
subject => 'this is a test message',
date => '10 June 2000, 10 minutes into the X-Files rerun',
author => 'chromatic',
id => '001',
children => [ 002, 004, 005 ],
text = 'Hello, this is just a test message.');
You could store that in a database or in a flat file somewhere. The important part is that you are keeping track of the threading in your persistent data structure. You'll have to come up with some way to update a parent message when someone replies to it, but getting your data structure right is 80% of the battle. | [reply] [Watch: Dir/Any] [d/l] |
$message{parent} = 003;
To go along w/ chromatic's structure. | [reply] [Watch: Dir/Any] [d/l] |
btrott and chromatic both have great suggestions.
As you are starting to look at storing structured data,
there some techniques you shoud consider:
If you have access to a database, you should use it.
Perl has a robust DBI module that provides
interfaces to many SQL databases (it even has
drivers that allow you to use flat files
as if they were SQL databases). You may also want to check
out the FreezeThaw, Data::Dumper and Storable
modules. All of those modules provide ways to taking an
in-memory data-structure and extracting it so it can
be stored (on disk or otherwise) for later retrieval.
If you have access to Advanced Perl Programming
it has an excellent chapter on data-persistance
that should really be in-line with what you're working
on.
| [reply] [Watch: Dir/Any] |