Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
: #!/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

In reply to Re: Re: Looking for feed back on a guestbook by CharlesClarkson
in thread Looking for feed back on a guestbook by Cobo

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2014-10-25 22:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (149 votes), past polls