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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



yim11
Novice

Jan 17, 2001, 6:22 PM

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

Hello,
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!
TIA!
-Jim
---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
$co->h3
("Posted by ", $username, " on ", $date,
$co->p,
$text,
),

$co->hr,
$co->end_html;

close BOOK;

print $co->header,
$co->start_html
( -title=>'Guest Book',
-BGCOLOR=>'black',
-Link=>'red',
-text=>'white'
);

print
$co->center
( $co->h2('Thanks for adding to the Guest Book!')
),
"To view the Guest Book, ",
$co->a
(
{href=>"book.htm"},
"click here"
),
".",
$co->hr,
$co->end_html;
---End Guestbook Code---




pu_nk
journeyman

Jan 17, 2001, 10:14 PM

Post #2 of 4 (267 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..

reverse(@array);

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





pu_nk
journeyman

Jan 17, 2001, 10:16 PM

Post #3 of 4 (267 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")
reverse<BOOK>;

that should do it i think

Drew
www.cgishack.com



sleuth
Enthusiast / Moderator

Jan 18, 2001, 1:32 AM

Post #4 of 4 (264 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
print;
}
}

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
<blablabla>sfdsdfsdf</bsdfsdf>
~;

Sleuth


 
 


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

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