I am still a beginner and am writing a very simple guestbook that writes the data to a file. My problem is that if the user should press the enter button while in the textarea to get a new line instead of waiting for the wordwrap then that also gets recorded to the file as a new line. When I read the file for output, anything on the new line(s) is missed because it is not a valid line containing an id number. How could I prevent this?
sub CheckForMsgs { my $strMsg = ''; my @MsgArray = (); my $MsgDate = 0; my $Message = ''; my $GuestName = ''; my $id = 0; my $colorflag = 0; my $bgcolor = "#FFFFCC"; # open the file for read open(DAT,"Guestbook.cgi") || die("Cannot Open File:$!"); @MsgArray = <DAT>; close(DAT); foreach $id (@MsgArray) { chomp ($id); ($id,$MsgDate,$GuestName,$Message)=split (/\|/,$id); # alternate table row background color to contrast entries. if ($id%2 eq 1){ $bgcolor = "#FFFFCC"; $strMsg .= "\ <tr bgcolor=\"$bgcolor\"><td> $MsgDate < +/td><td align=center> $GuestName </td><td> $Message </td></tr> \n"; } else { $bgcolor = "#DFDF00"; $strMsg .= "\ <tr bgcolor=\"$bgcolor\"><td> $MsgDate < +/td><td align=center> $GuestName </td><td> $Message </td></tr> \n"; } } return $strMsg; }; ####End of Sub sub WriteNewMsg { my @MsgArray = (); my $id = 0; my $NewMsg = ''; my $GuestName = ''; my $now_string = strftime "%a %b%e %H:%M %Y", localtime; my $NewID = 1; &ReadParse(*input); # open the file for read open(DAT,"Guestbook.cgi") || die("Cannot Open File:$!"); @MsgArray = <DAT>; close(DAT); open(DAT,">>Guestbook.cgi") || die("Cannot Open File:$!"); foreach $id (@MsgArray) { chomp ($id); ($id,$MsgDate,$GuestName,$NewMsg)=split (/\|/,$id); ++$NewID; } # add Event to file print DAT "$NewID|$now_string|$input{'txtGuestName'}|$input{'txtMs +g'}\n"; close(DAT); }; ###End of Sub

In reply to Simple guestbook problem. by engtech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.