CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Help with guestbook needed



Jan 17, 2001, 6:22 PM

Post #1 of 4 (380 views)
Help with guestbook needed Can't Post

I have the following guestbook, that works great - except new entries in the book are added to the bottom of the page, and I would like to change the script so that new entries are displayed at the top of the page. Any and all help with this is greatly appreciated!
---Begin Guestbook Code---
use CGI;

$co = new CGI;

open (BOOK, "+<book.htm")
or die "Could not open guest book.";

seek (BOOK, -length($co->end_html), 2);
$date= localtime;

$username = $co->param('username');
$username =~ s/</</g;
$text = $co->param('comments');
$text =~ s/</</g;

print BOOK
("Posted by ", $username, " on ", $date,


close BOOK;

print $co->header,
( -title=>'Guest Book',

( $co->h2('Thanks for adding to the Guest Book!')
"To view the Guest Book, ",
"click here"
---End Guestbook Code---


Jan 17, 2001, 10:14 PM

Post #2 of 4 (371 views)
Re: Help with guestbook needed [In reply to] Can't Post

you will want to use the reverse function that perl has..

i did not really read through your code casue i am just loggin off but here is a quick example..


this will reverse the contents in the array so your guestbook will display its entries at the top.


Jan 17, 2001, 10:16 PM

Post #3 of 4 (371 views)
Re: Help with guestbook needed [In reply to] Can't Post

Yikes.. you dont use an array to hold the information..

ok.. try this
Where you have this line.... add the following...

open (BOOK, "+<book.htm")

that should do it i think


Enthusiast / Moderator

Jan 18, 2001, 1:32 AM

Post #4 of 4 (368 views)
Re: Help with guestbook needed [In reply to] Can't Post

Yim11, just for future reference, you can insert lines directly into a file. Top middle where ever. Since your writing to an html file and not a database I'm sure you'll want to use this method because you can't just write to the top of the file or you'll be writing above the head and body tag, so I don't think a reverse sort will work for html files (No Offense pu_nk :).

Japhy taught me this, it's even in the FAQ.

$filename = "test.db";
local $^I = "";
local @ARGV = $filename;
while (<>) {
print "$HTML" if $. == 10; # fix 10 to the right line number

The line number you should fix 10 to is the place where you want the html to insert into with each submission.

Also, make sure all output from your script is stored into $HTML instead of printing it directly. Makes it easier to follow.

$HTML = qq~
all the generated html here



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives