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

Alright, I told myself that I would figure it out by myself, but I can't do it, so this is my cry for help, yet again, to the Perl brotherhood:
#! /usr/local/bin/perl -w use strict; use CGI qw(:standard); my $q=CGI->new(); open(FH,"+>>message.txt") || die("Cannot Open Data File.. Error"); seek(FH, 0,0); my $data = <FH>; print "Content-type:text/html\n\n"; print $q->start_html("My Message Board"); print "<h2>My Message Board</h2><br><hr>"; print $data; print "<p><hr><br>Post:<br>"; print "<center><form action=\"hw5.pl\" method=\"POST\">"; print $q->textarea(-rows=>6, -columns=>75, -name=>'text'); print "<br>"; print $q->submit(-value=>'Submit When Completed', -name=>'submit'); print "</form></center>"; print $q->end_html(); my $value=$q->param('text'); $value =~ s/\+/ /; $value =~ s/\r//g; $value =~ s/\n/ /g; print FH "$value"; close(FH);
I'm getting errors where I try to print the $data, and again where I try to change my incoming $value to be appended. Any point in the right direction, or words of wisdom would be appreciated.

Thanks,

alarthame

Update! I fixed that code a bit to reflect where I am right now. Thanks to Enlil for that little note that dealt it with the +>> I think that did it.

I'm still trying to get it so it won't tag on blank lines when I refresh the page. I've tried putting a line that stops the post if it's null, down by the $value, but that doesn't seem to work. Also, I'm not quite sure how to reset the textfield on a refresh. It like to repost the last entry or a blank field.

Replies are listed 'Best First'.
Re: Another Simple Message Board
by Enlil (Parson) on Nov 08, 2003 at 02:48 UTC
    I believe that
    open(FH,">>message.txt")
    will only make your filehandle available for appending to the end of a file. Changing it to "+>>message.txt", will make it available for reading as well. I don't know that your seek is of any use, or why it is there (been a long time since I have used it and so i might be mistaken).

    apart from that:

    $value =~ s/+/ /;
    should be
    $value =~ s/\+/ /;
    as + is special in a regular expression.

    Update:changed the second bit (i.e. s/\+~/=~/; Thanks Chady++

    -enlil

Re: Another Simple Message Board
by pg (Canon) on Nov 08, 2003 at 02:31 UTC

    When I ran it, it gave me error on line 23.

    $value =~ s/+/ /;

    + is just a quantifier, what is the object being quantified? I guess you mean:

    $value =~ s/\s+/ /g;

    BTW, as you used the CGI module, why didn't you use CGI functions to generate html tags like "form"? try to use those functions to reduce malformated tags.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Another Simple Message Board
by sweetblood (Prior) on Nov 08, 2003 at 02:35 UTC
    looks like you trying to read past the end of your file. Check the perldoc for seek.

    Happy hunting!

      Don't I want to go to the end of the file for appending to it?