sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
What works: Posting short sentances not containing anything which invokes a substitution such as "My dog is painted red because of his underbite".
What doesn't work: The opposite; anything invoking any of the substitutions below (emoticons or swear filter) such as ":) :( hi there, Joe"
What happens when it doesn't work: The database will work properly until a certain number of key/value pairs are recorded which contain substitution reference. The database will then refuse to accept every new message (it accepts SOME new messages, not all) you try to send along with post it out of order. Insertion order is lost if you post around 19 messages which contain smiley faces.
What was suggested: Perhaps I am exceeding the key/value limit of 1008 bytes for SDBM. As far as I know this cannot be the case for this specific problem because posting plain sentances continues to work as far as I could test while a five character phrase ":) :(" crashes it in just a few messages.
Other: After rereading the code all night I thought I found the problem (I was making all the subs before saving it to $chat meaning the whole URL was always included which possibly exceeded the limit). I moved it further down so it doesn't affect the DB at all.
Can someone help me figure out why this chat will work under normal text conditions but crash because of simple substitutions?. The url is http://sulfericacid.perlmonk.org/chat/chatgood.pl if you want to test it. Try adding :) and :( until message 15-20 to see what it does.
use Tie::IxHash; my $columns = 50; use Text::Wrap qw( wrap $columns ); require SDBM_File; my %chat; my %chatorder; my @words = (); my $chat = "list.dbm"; # location of database my $file = "count.txt"; # location of count file my $url = "http://sulfericacid.perlmonk.org/chat/chatgood.pl"; my $imagedir = "http://sulfericacid.perlmonk.org/chat/images"; + # location of image directory (emoticons) tie %chat, "Tie::IxHash"; tie %chatorder, "Tie::IxHash"; tie %chat, 'SDBM_File', $chat, O_CREAT | O_RDWR, 0644; if ( !tied %chat ) { print "database unsuccessful $!.\n"; } $|=1; # maybe this will help page refreshing my $js="<script langauge=\"Javascript\"> document.write('<form><input type=button value=\"Refresh\" onClick=\"w +indow.location.reload()\"></form>');</script></noscript></noscript>"; # # Time to keep accurate logs # my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); print header, start_html; my $num; foreach (keys (%chat)) { $num++; } print "DB keys: $num"; my $name = param('name'); my $message = param('message'); my $cnt; if (param) { if ($name) { if ($message) { open( LOG, "$file" ); # open count log for ID $cnt = <LOG>; close(LOG); $cnt++; open( LOG, "> $file" ); print LOG $cnt; close(LOG); $name =~ s/</<\;/g; # removing exploit $message =~ s/</<\;/g; # removing exploit my $keeptime = join (':', $hour, $min, $sec); my $info = join ( '::', $name, $message, $keeptime ); $chat{$cnt} = $info; } else { print "Message was missing, data not sent.<br>"; } } else { print "Name was missing, data not sent.<br>"; } } print "(<a href=\"log.pl\" target=\"new\">chat logs</a>)"; print "the local time is $hour:$min:$sec"; print start_table; print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"<font si +ze=2><b>ChatterBox version 1.0</b> $hour:$min:$sec</font>" )); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); my $add; foreach (reverse keys (%chat)) { $add++; if ($add <= 10) { $chatorder{$_} = $chat{$_}; } } foreach (reverse keys (%chatorder)) { my ( $name, $message, $time ) = split /::/, $chatorder{$_}; $name =~ s/$_/****/g for @words; # say goodbye to swear words $message =~ s/$_/****/g for @words; # say goodbye to swear words $message =~ s/:\)/\<img src=\"$imagedir\/smiley.gif\"\>/g; # happy emo +ticon $message =~ s/:\(/\<img src=\"$imagedir\/sad.gif\"\>/g; # sad emoti +con $message =~ s/:p/\<img src=\"$imagedir\/tongue.gif\"\>/g; # tongue em +oticon $message =~ s/:P/\<img src=\"$imagedir\/tongue.gif\"\>/g; # tongue1 e +moticon $message =~ s/:o/\<img src=\"$imagedir\/oh.gif\"\>/g; # oh emotic +on $message =~ s/:O/\<img src=\"$imagedir\/oh.gif\"\>/g; # oh1 emoti +con $message =~ s/\*hug\*/\<img src=\"$imagedir\/hug.gif\"\>/g; # hug emo +ticon $message =~ s/\*flower\*/\<img src=\"$imagedir\/flower.gif\"\>/g; # f +lower emoticon $message =~ s/\*wink\*/\<img src=\"$imagedir\/wink.gif\"\>/g; # wink +emoticon $message =~ s/\*devil\*/\<img src=\"$imagedir\/devil.gif\"\>/g;# devil + emoticon $message =~ s/\*love\*/\<img src=\"$imagedir\/love.gif\"\>/g; # love +emoticon $message =~ s/\*sleep\*/\<img src=\"$imagedir\/sleep.gif\"\>/g;# sleep + emoticon $message =~ s/\*conf\*/\<img src=\"$imagedir\/confused.gif\"\>/g;# sle +ep emoticon $message = wrap('', '', $message); print Tr(td({-width=>'700'},"<font color=blue><$name @ $time> +;</font>$message")), } print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"<font si +ze=2><p align=right><b>http://sulfericacid.perlmonk.org</b></font>" ) +); print start_form(-action=>$url), table( Tr( td("Name: "), td( textfield( -name => 'name', -size => 40 ) ) ), Tr( td("Message: "), td( textfield( -name => 'message', -size => 100, -force=>1, ) ) ), Tr( td(), td(submit('send'), $js), ), end_form(), hr(), );
update (broquaint): added <readmore> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: database problems: repost
by bobn (Chaplain) on Jun 28, 2003 at 15:07 UTC | |
|
(jeffa) Re: database problems: repost
by jeffa (Bishop) on Jun 28, 2003 at 17:01 UTC |