#!/usr/bin/perl require 'utility2.pl'; &form_handler; $textdir = "../../data/text"; $docfile = "../../htdocs/cowboys/$FORM{'3'}"; for ($count = 1; $count < 5; $count++) { if ($FORM{'$count'} =~ /\//g || $FORM{'$count'} =~ /\.\./) { error(); +exit; } } use POSIX; $date = strftime("%H:%M %m/%d/%Y",localtime); open (OLDCHAT, "$textdir/$FORM{'1'}") || die "text file doesn't exist" +; @old = <OLDCHAT>; ##get copy of old comments open (ADDCHAT, ">$textdir/$FORM{'1'}"); #empty old comments $FORM{'name'} =~ s/\<+.+\>*//g; $FORM{'location'} =~ s/\<+.+\>*//g; $FORM{'comments'} =~ s/\<+.+\>*//g; $FORM{'comments'} =~ s/\n+//g; open (BAD, "$textdir/bad.txt") || die "can't open bad"; @bad=<BAD>; foreach $bad(@bad) { chop ($bad); if ($FORM{'comments'} =~ /$bad/ig) { $FORM{'comments'} =~ s/$b +ad/\%\$\#\&\!\%/gi; next;} } print ADDCHAT ("<H4>$FORM{'name'} from $FORM{'location'} said:</h4> $F +ORM{'comments'} <BR> <H6>$date</H6><P> <!--$ENV{REMOTE_HOST}--><HR>\n +"); #print new comment on top for (@old) { s/\s+/ /g; s/\n+//g; s/<HR>/<HR>\n/g; } if (scalar @old>200) { pop(@old) until scalar @old < 200; } print ADDCHAT @old; #add old comments close ADDCHAT; open (TOP, "$textdir/$FORM{'2'}"); @top = <TOP>; open (CHAT, "$textdir/$FORM{'1'}"); @new = <CHAT>;#get copy of updated comments open (NEWCHAT, ">$docfile") or &debug($FORM{'3'}); select(NEWCHAT); &html_header("$FORM{'4'}"); print "@top"; print "@new"; &html_footer; close NEWCHAT; select(STDOUT); print "Location: http://www.example.com/cowboys/$FORM{'3'}\n\n"; exit(0); sub error { print "Content-type: text/html\n\n"; &html_header("Error"); print<<"GOOF"; A system error occrred. Perhaps you tried to use an illegal character. GOOF &html_footer; 0; } sub debug { my $debugpage = shift(@_); print "Content-type: text/html\n\n"; &html_header("Error"); print<<"GOOF"; Could not open $debugpage for writing! GOOF &html_footer; 0; }

In reply to Is this code in Perl or CGI? by perl2010

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.