I'm writing a tutorial for Guru's on Perl/CGI and before I got into the actual tutorial writing, I was wondering if I could get a review of the code.
The purpose is simple:
- Display news items stored in flat file database (sort of like a blog)
- Sort news items by date and display a paged view
- Add news items
The basic algorithm for displaying news is:
- read news items from database and store them in an associative array using the timestamp as the key and an array reference to the array holding the information
- print them out in a paged view depending on $newsitemsperpage value in config file, including navigation
The basic algorithm for modifying news is:
- check if there are any parameters passed into the script
- if there are parameters passed in, assume that this is a new item to be added
- read news items from database and store them in an associative array using the timestamp as the key and an array reference to the array holding the information
- create a new timestamp for the news item, making sure that this isn't a duplicate (if so, create a new timestamp)
- add news item to database
- if there are no paramaters passed into the script, display form to add news item
The database is a flat text file in the following format:
code:
1099666755
test 14
test test test test test test
test test test testtest test test test
test test test test
test test test testtest test test
test test test test
test test test testtest test test test
test test test testtest test test test
test test test test
---- NEWSBLOCK ----
The first line of each block is the time stamp. This is UTC. The second line is the subject and all additional lines are content. Each block is separated by "---- NEWSBLOCK ----" on the last line.
There are 3 documents:
- displaynews.pl - displays news items
- modifynews.pl - add news item (modify functionality may be added later
- config.pl - global variables and some subroutines
What I'm looking for is c+c regarding the way things are coded, other simpler/better ways of doing certain things, algorithmic improvements, etc.
Here are the pages:
http://members.optusnet.com.au/aanesi/ozone/displaynews.pl
http://members.optusnet.com.au/aanesi/ozone/modifynews.pl
http://members.optusnet.com.au/aanesi/ozone/config.pl
These versions don't work since my host doesn't provide server side scripting, but I can post a working version if that will help.
(Edited by silence on 12-22-2004 17:34)
(Edited by silence on 12-22-2004 17:37)