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