My current forum uses flat text files and reads/writes the entire file when adding a new message.
I'd like to look into using fixed length files for indexes etc for faster and more efficient data handling.
I've searched, googled and even downloaded example forums, but cannot see examples.
Can anyone point me to some example of good record handling - eg using seek etc to only update the records required. If its code specifically for a forum all the better!!!
Edited 1 Jan 2006, by footpad: Added basic formatting tags.
Why don't you use one of the fifteen million solutions already in existance?Why not be helpful and point him to at least one of them since they are indeed so copious?
thor
The only easy day was yesterday
You may view the original node and the consideration vote tally.
You may view the original node and the consideration vote tally.
Honestly I figured he already knew about them. I mean, who hasn't heard of mysql? Or postgresql, or berkeley database, and so on?Obviously, he didn't. Or at least he didn't think to apply one of those solutions to his problem. Also, you could have just answered "you may want to try a database solution" instead of being vague. Sometimes, even a little bit of info (and courtesy) go a long way.
thor
The only easy day was yesterday
You may view the original node and the consideration vote tally.
You may view the original node and the consideration vote tally.
Are you sure you want to use fixed-length record sizes for forum posts? Do you have a small maximum length for the body of the post? If not, all of your records will be the size of the largest possible record -- and if that's not small, you'll have to do a lot of IO to read each message from the disk, pull it through the cache, and get it where perl can handle it. If you really think that will improve your speed (and I don't, even without benchmarking it), you need some sort of unique ID per message which you can use as an offset into the file. Multiply that by the size of a record and use seek and sysread on a filehandle to extract just the record you want.
If that doesn't seem fun to you (and it's not), you could use a unique record separator between records and let CPAN://Tie::File take care of reading and writing.
If this were my project, I would use CPAN://DBD::SQLite and avoid all of the tedious mucking about with O(n) access and let indexed columns get that down to O(log n) or better, while not having to process all of the data myself. Please consider that instead.
You may view the original node and the consideration vote tally.
It would, however, be simpler to just do this with mySQL. Certain things like indexes can get quite complicated to program.
perlmonks.org content © perlmonks.org and BUU, chromatic, holli, NeilF, NodeReaper, TedPride, thor
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03