Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Help!
by btrott (Parson) on Apr 24, 2000 at 10:19 UTC
    Without looking at it very closely, this looks very wrong:
    open (TEXT,">text.txt"); ... @text=<TEXT>;
    You open test.txt (you should be checking the returns of your opens and any other function that uses the system!) for writing, then you try to read from it. I don't think that's going to work like you want it to, at all.

    And in fact what you've done is overwritten what was already in @text. What do you want in @text, anyway? Basically everything in test.txt previously, plus the new stuff?

    There are several ways to do this, but one of the simplest is this:

    • open test.txt for appending (">>")
    • write the new data to it
    • close it
    • open it for reading
    • read all data from it, into @text
    • close it
    You should also throw in some file locking for both files (test.txt and forum.html)--lookup flock.

    And check the return status of your open calls! :)

    If this doesn't help, be more specific about what isn't working.

Re: Help!
by chromatic (Archbishop) on Apr 24, 2000 at 18:52 UTC
    You might try this for your form definition: <form method = "GET" action = "forum.pl"> POST will work as well, but using GET will show the parameters in the URL so you can do some quick visual debugging there. (I'm not a JavaScript guru, so that part jumped right out at me.)
Re: Help!
by BBQ (Curate) on Apr 24, 2000 at 17:31 UTC
    The cool thing about forums is that you have 3426 different ways to store stuff depending on what you want you're forum to do... The basic design of your forum is correct, but you might want to consider opening new files for each of the comments posted. Ie:
    # put all posts in ./msgs open(WRITE,">msgs/$^T.txt") or die(); print WRITE "<P>",$query->param('name'); print WRITE "<P>",$query->param('subject'); print WRITE "<P>",$query->param('message'); close(WRITE); # ... # and later when you're making up the page... # sort the messages by date foreach $msg (sort glob('msgs/*.txt')) { open(READ,$msg) or warn($!); @msg = <READ>; close(READ); print FORUM "@msg\n"; }
    By doing this, you can later on make is so that each one of you're posters can re-edit his own post, generate stats, clean-up old messages and other cool things of the sort...

    Forums were the way that I learned perl in the 1st place. Forums are fun!

    #!/home/bbq/bin/perl
    # Trust no1!
Re: Help!
by turnstep (Parson) on Apr 24, 2000 at 21:08 UTC
    Also, if you'd like to get rid of those ugly string concanenation operators (aka periods) you can say:
    print FORUM qq[<HTML><BODY BGCOLOR="BLACK" TEXT="RED"> <CENTER>Grettingz,<BR>Thiz iz a forum for fellow members of Clan Titan +. to discuss issues and just generallly unwind, ask questions etc.<BR>. Alzo, ppl who are new to thiz forum, plez make a pozt saying you are. here, or even better, write a story about<BR>". how you came to be here! thanx!<BR>". Menttal<BR>Founder of Clan Titan<P><P><P><P>\n];
    Not only is it easier to write, and it allows you to use real quotes, but easier to read the HTML produced: your code as it was put all of your text on a single line!