Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can someone look over this script?

0 views
Skip to first unread message

Phantom

unread,
Jul 27, 1998, 3:00:00 AM7/27/98
to
Hello Everyone, I have recently learned Perl and I wrote my first guestbook
script. The only problem with it is that it overwrites the actual
guestbook.html with only one entry. I put in a line to tell it to look for
it then write after it, but it doesn't. Can someone Please point out the
problem? The following is a link to the script in txt format:

http://www.concentric.net/~virtuous/guestbook/guestbook.pl.txt

--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content. You can SELF-APPROVE your first posting
by writing the word 'passme' on a line by itself.

Rick Millar

unread,
Jul 27, 1998, 3:00:00 AM7/27/98
to
Try adding a second ">>" to your open statement so that you will append
to the file instead of overwriting it. That may help if there are no
other problems.

open (GBOOK,">>$book_url") || die "Could Not Open $book_url: $!\n";

instead of:

open (GBOOK,">$book_url") || die "Could Not Open $book_url: $!\n";

Rick


Phantom wrote:
:
: Hello Everyone, I have recently learned Perl and I wrote my first guestbook

Thomas Jespersen

unread,
Jul 27, 1998, 3:00:00 AM7/27/98
to
Phantom wrote:
:
: Hello Everyone, I have recently learned Perl and I wrote my first guestbook
: script. The only problem with it is that it overwrites the actual
: guestbook.html with only one entry. I put in a line to tell it to look for
: it then write after it, but it doesn't. Can someone Please point out the
: problem? The following is a link to the script in txt format:
:
: http://www.concentric.net/~virtuous/guestbook/guestbook.pl.txt
.

1. Remember to lock your file before writing to it :

(look at flock in the perl documentation).


2.
: open (GBOOK,">$book_url") || die "Could Not Open $book_url: $!\n";

this line will truncate the file pointed to by GBOOK and write to it.
You only write the form entries which was just submitted. Change it to:

open (GBOOK,">>$book_url") || die "Could Not Open $book_url: $!\n";

now it is opened for appending. (notice two '>')

jay_e...@my-dejanews.com

unread,
Jul 28, 1998, 3:00:00 AM7/28/98
to
In article <6piq6r$p...@examiner.concentric.net>,

"Phantom" <virt...@concentric.net> wrote:
: Hello Everyone, I have recently learned Perl and I wrote my first guestbook
: script. The only problem with it is that it overwrites the actual
: guestbook.html with only one entry. I put in a line to tell it to look for
: it then write after it, but it doesn't. Can someone Please point out the
: problem? The following is a link to the script in txt format:

I suspect that the line
print GUEST ("$line");
should really be
print GBOOK $line ;
because you don't have a file handle anywhere in the script named GUEST. I
assume you're opening the guestbook HTML file, reading the whole thing, the
opening it for writing (thus erasing the whole thing), writing it back from
memory until you find a certain HTML comment, then writing the new entry, then
writing the rest of the file from memory. Unfortunately, it's that last part,
writing the rest of the file from memory that's not happening because it's
trying to print to a file handle that doesn't exist.

Good luck.

PS-take a look at implementing the comments from the other posts like file
locking, etc. The problem I found is just one of the problems you might
encounter with the script.

--
Jay Eckles
www.ecklesweb.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

Phantom

unread,
Jul 28, 1998, 3:00:00 AM7/28/98
to

Thank you for everyone who helped me fix my script. I couldn't have done it
without your help. And the script is finally working the way I wanted it to!

Thanks Again,
Mark.

0 new messages