chat.pl #!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw(:standard start_table end_table); use lib ""; use DB_File; use Text::Wrap; my %chat; my %chatorder; my @words = (); my $chat = "chat.db"; # location of database my $file = "count.txt"; # location of count file my $url = "http://sulfericacid.perlmonk.org/chat/chat1.pl"; my $imagedir = "http://sulfericacid.perlmonk.org/chat/images"; # location of image directory (emoticons) tie %chat, "DB_File", "$chat", O_CREAT|O_RDWR, 0644, $DB_BTREE or die "Cannot open file 'chat': $!\n"; print header, start_html; my $js=""; my $name = param('name'); my $message = param('message'); my $cnt; ## Get the user information if (param) { if ($name) { if ($message) { open( LOG, "$file" ); # open count log for ID $cnt = ; close(LOG); $cnt++; open( LOG, "> $file" ); print LOG $cnt; close(LOG); $name =~ s/"; } } else { print "Name was missing, data not sent.
"; } } # Start printing everything out my $cnt = 0; foreach (keys %chat) { $cnt++; } print qq[(chat help) ]; print "(chat logs)"; print start_table; print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"ChatterBox version 1.0" )); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); for (grep defined($_), (keys %chat)[-10..-1]) { my ( $name, $message,) = split /~~/, $chat{$_}; $name =~ s/$_/****/g for @words; # say goodbye to swear words $message =~ s/$_/****/g for @words; # say goodbye to swear words $message =~ s#:\)##g; # happy emoticon $message =~ s#:\(##g; # sad emoticon $message =~ s#:p##g; # tongue1 emoticon $message =~ s#:o##g; # oh emoticon $message =~ s#:O##g; # oh1 emoticon $message =~ s#\*hug\*##g; # hug emoticon $message =~ s#\*flower\*##g; # flower emoticon $message =~ s#\*wink\*##g; # wink emoticon $message =~ s#\*devil\*##g;# devil emoticon $message =~ s#\*love\*##g; # love emoticon $message =~ s#\*sleep\*##g;# sleep emoticon $message =~ s#\*conf\*##g;# sleep emoticon $message = wrap('', '', $message); print Tr(td({-width=>'700'},"<$name>$message")), } print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"")); print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},"

http://sulfericacid.perlmonk.org" )); 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(), ); #### log.pl #!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw/:standard/; use DB_File; my $add; my %chat; my $chat = "chat.db"; tie %chat, "DB_File", "$chat", O_CREAT|O_RDWR, 0644, $DB_BTREE or die "Cannot open file 'chat': $!\n"; print header, start_html; print "

CB History- last 100 things seen...

"; print ""; for (grep defined($_), (keys %chat)[-100..-1]) { my ( $name, $message, $time ) = split /~~/, $chat{$_}; print ""; } print "
"; print "<$name> $message"; print "
";