Gossamer Forum
Home : General : Perl Programming :

Guestbook ANTI-HACK

Quote Reply
Guestbook ANTI-HACK
Sometimes jokes add the following to my guestbook wich corrupt my layout!

Code:
hahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahaha hahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahah ahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahah ahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahaha hahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahaha hhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahah ahahahahahahahahhahahahahahahahahahahahahahahahhahahahahahahahahahahahahahahahhahahahahaha

That's why i would like to check the comments field. I would like to limit the maximum characters a word in the comments field could have; something like:

Code:
# delete long words (to protect layout)
@comments = split (/\s/, $in{'comments'});
foreach $long_word (@comments) {
if ($long_word >= 20) {
$censor = 1;
$mailadmin = 1;
}
}

BUT it's not working, could anyone help me out?
Quote Reply
Re: Guestbook ANTI-HACK In reply to
You need to tell it to look at the length of the long word.

Code:
if (length($long_word) >= 20) {


------------------
JPD






Quote Reply
Re: Guestbook ANTI-HACK In reply to
another one:
Code:
@chars = split(//,$word);
foreach $char (@chars) { $a++; }
if ($a > 20) { &error; }
Quote Reply
Re: Guestbook ANTI-HACK In reply to
You could always perform the entire process of splitting apart the submitted comment and testing in one line:
s/([^ ]){20}/{$censor = 1; $mailadmin = 1}$1/e foreach (split(/ /, $comments));

-- Gordon


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);

Quote Reply
Re: Guestbook ANTI-HACK In reply to
Why would you suggest a setting an array up using spilt, running through a foreach loop, incrementing a counter, and then performing the if, when the simple "if length..." is a simple built in funtion? going though that entire thing is like reinventing the wheel, except sub-optimally.

Benchmark test between the two:

Benchmark: timing 1000000 iterations of foreach, length...
foreach: 171 wallclock secs (170.55 usr + 0.00 sys = 170.55 CPU) @ 5863.38/s (n=1000000)
length: 1 wallclock secs ( 0.78 usr + 0.00 sys = 0.78 CPU) @ 1282051.28/s (n=1000000)

I'd say the length function is juuussssssssst a tad better Smile Smile

--mark
Quote Reply
Re: Guestbook ANTI-HACK In reply to
Cool stuff, would any of you guys mind if I used a bit of that code in a script I'm toying around with? :)