Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Looking for feed back on a guestbook

by Cobo (Scribe)
on Nov 15, 2001 at 20:42 UTC ( #125610=note: print w/ replies, xml ) Need Help??


in reply to Looking for feed back on a guestbook

It was asked that I post my alterations, Well I haven't tested it yet but heres my second draft.

#!/usr/bin/perl -w use strict; use CGI ':standard'; use Regexp::Common qw(RE_profanity); print header(); print start_html(); print "<html><head><title>Thanks for Signing!</title></head>"; print "<body bgcolor=black text=white>"; my $q=new CGI; my $name =$q->param('name'); my $mail =$q->param('mail'); my $message =$q->param('message'); print "<center><p>Thanks for signing my guestbook, your message +has been posted! $name!</center></p>"; # REMOVE THIS COMMENT TO ACTIVATE CENSOR $message =~ s/$RE{profanity}/ +bleep/msg; foreach ($name,$mail,$message) { s/</&lt;/g; s/>/&gt;/g; }; foreach ($message,$mail,$name){ s/\(b\)/<b>/ig; s/\(i\)/<i>/ig; s/\(\/b\)/<\/b>/ig; s/\(\/i\)/<\/i>/ig; }; foreach ($message,$mail,$name) { s/\(red\)/<font color=red>/ig; s/\(\/red\)/<\/font>/ig; }; if ($message =~ /\(red\)/i and $message =! /\(\/red\)/i) {$message=$me +ssage."</font>"}; print "Name: $name <br> Email: $mail <br> Message: $message"; open HTML, ">>../gbook.html" or die $!; print HTML "<i>Name:</i> $name <br> <i>E-Mail: </i>$mail<br> <i>Messag +e: </i>$message <p>"; close HTML; print "</BODY></HTML>";
I've used a couple of the suggestions so far, when I get home I'll mess around with it more. And thank you all for the comments, I found them very helpful.


Comment on Re: Looking for feed back on a guestbook
Download Code
Re: Re: Looking for feed back on a guestbook
by tomhukins (Curate) on Nov 15, 2001 at 21:58 UTC
    I find s!\(/b\)!</b>!ig marginally easier to read than s/\(\/b\)/<\/b>/ig;. If you need to escape the / within a regexp, it's often best to use a different delimiter.
Re: Re: Looking for feed back on a guestbook
by CharlesClarkson (Curate) on Nov 16, 2001 at 02:01 UTC
    : #!/usr/bin/perl -w : use strict; : use CGI ':standard';
    For some reason, center is not included in :standard. If we lead an item with *, we can use start_ and end_ (*html is included in :standard.)
    use CGI qw/:standard center *font *i *b/; : use Regexp::Common qw(RE_profanity);
    No need to load this unless we're using it. (Moved down page.)
    : print header(); : print start_html(); : : print "<html><head><title>Thanks for Signing!</title></head>"; : print "<body bgcolor=black text=white>";
    This can be combined into:
    print header, start_html( -bgcolor => 'black', -text => 'white', -title => 'Thanks for Signing!'); : my $q=new CGI; : my $name =$q->param('name'); : my $mail =$q->param('mail'); : my $message =$q->param('message');
    This uses CGI.pm as an object. We called CGI in the function oiented style. Most everyone agrees - don't mix the two styles.
    my $name = param('name'); my $mail = param('mail'); my $message = param('message'); : print "<center><p>Thanks for signing my guestbook, your", : "message has been posted! $name!</center></p>";
    With center defined:
    print center( p( 'Thanks for signing my guestbook, your message ', "has been posted! $name!" )); : # REMOVE THIS COMMENT TO ACTIVATE CENSOR # use Regexp::Common qw(RE_profanity); : # $message =~ s/$RE{profanity}/bleep/msg; : : foreach ($name,$mail,$message) { : s/</&lt;/g; : s/>/&gt;/g; : }; : : foreach ($message,$mail,$name){ : s/\(b\)/<b>/ig; : s/\(i\)/<i>/ig; : s/\(\/b\)/<\/b>/ig; : s/\(\/i\)/<\/i>/ig; : }; : : foreach ($message,$mail,$name) : { : s/\(red\)/<font color=red>/ig; : s/\(\/red\)/<\/font>/ig; : };
    These foreach blocks can be combined. I used function calls for the HTML and variables for (red) and (/red) to improve readability (TIMTOWTDI).
    my ($red, $sl_red) = qw|\(red\) \(/red\)|; foreach ($name, $mail, $message) { s/</&lt;/g; s/>/&gt;/g; s|\(b\)|start_b|ieg; s|\(i\)|start_i|ieg; s|\(/b\)|end_b|ieg; s|\(/i\)|end_i|ieg; s/$red/start_font({-color => 'red'})/iego; s/$sl_red/end_font/iego; } : if ($message =~ /\(red\)/i and $message =! /\(\/red\)/i) { : $message=$message."</font>" : };
    This is useless since we have already replaced all occurrences of (red) and (/red). Perhaps we could count successful matches or place this if block before the foreach block.: print    "Name: $name <br> Email: $mail <br> Message: $message";
    Let's move this down and combine it with the ending.
    : open HTML, ">>../gbook.html" or die $!; : print HTML "<i>Name:</i> $name <br> <i>E-Mail: </i>$mail<br> ", : "<i>Message: </i>$message <p>";
    Or perhaps:
    print HTML i('Name: '), $name, br, i('E-Mail: '), $mail, br, i('Message: '), p($message); : close HTML; : print "</BODY></HTML>";
    Let's add the print from above and use it with CGI.pm.
    print "Name: $name", br, "Email: $mail", br, "Message: $message", end_html; __END__



    HTH,
    Charles K. Clarkson

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://125610]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-09-19 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (140 votes), past polls