Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Looking for feed back on a guestbook

by CharlesClarkson (Curate)
on Nov 16, 2001 at 02:01 UTC ( #125697=note: print w/ replies, xml ) Need Help??


in reply to Re: Looking for feed back on a guestbook
in thread Looking for feed back on a guestbook

: #!/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


Comment on Re: Re: Looking for feed back on a guestbook
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-10-23 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls