Ahhh, perl!
Armed & Hammered's suggestion works but I don't feel it's that good. The reversal of data would require a SSI call to a program to do it and whatever savings in adding an item would be more than offset in the overhead involved everytime the document is viewed. This holds unless you actually have more people adding data than simply viewing the listing, which is unlikely.
NetRodent's response is better, in that it concentrates the resource usage to only when adding a new listing and then simply echos the list when it's viewed. However, the "print" statements are not going to the file handle he opened (OOPS!), one should always check for the failure of file operations and, most importantly, there has to be a way of locking the code in a CGI enviroment when you're doing file operations. Otherwise, you run the risk of two seperate processes colliding and the list will be corrupted from that point forward.
Code:
$file = '/path/to/list.txt';
open(FILE, "+< $file") or die "can't open $file: $!";
flock(FILE, 2)
@lines = <FILE>;
# Write the new addition first
(print FILE "$newdata\n") or die "can't write to $file: $!";
# Copy original to new
while (@lines) {
(print FILE $_) or die "can't write to $file: $!";
}
# No need to explicitly unlock,
# "close" does it for us
close(FILE) or die "can't close $file: $!";