A few more pence in the pound:
(1) I'd use a module for stripping those tags, especially since you want to allow some and disallow others. I've not looked at this before, but there's bound to be one somewhere... searches
CPAN for HTML stuff... well, just from glancing at the docs, looks like
HTM::TagFilter would do just what you want. Looks as though it wd let you be pretty flexible abt what html you allowed your users, in an easy to maintain kind of way.
(2)
Wog alluded to this one in a different context: you cd do your censor in one regex:
$message =~ s/badword2|badword3|badword/bleep/ig;Although n.b. you have to be a little careful with the order of your search words, if some of them "contain" others. You notice I have
badword2|badword3|badword
instead of
badword|badword2|badword3
because the latter wd turn "badword2" into "bleep2".
(3) About printing out, I agree with the monks who say
use CGI or die;, and also those who say that if you do
use CGI qw/:standard/;
You don't need then to do
my $q = new CGI; # and all the $q-> method calling
My preference in a short script (or in any script, because I have only a limited understanding of OO programming) is the former. Then you could do all your printing right at the end, after munging around your
$message etc variables, with these lines which (and I agree beauty is in the eye of the beholder) I think are elegant and easy to read:
print
header,
start_html,
p(
{-align => center},
"Thanks for signing my guestbook, your message has been posted
+! $name!",
),
"Name: $name", br, "Email: $mail", br, "Message: $message",
# ok, line above is a *bit* CGI-obsessive
end_html;
Hope that's some use.
Please do post your revised code when you're finished with it, as it makes the thread a more complete learning resource for future generations.
§
George Sherston
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.