use strict;
use warnings;
use POSIX;
use CGI qw(:standard start_table end_table);
use lib "";
use Tie::IxHash;
my $columns = 50;
use Text::Wrap qw( wrap $columns );
use DB_File;
my %chat;
my %chatorder;
my @words = ();
my $chat = "chat.dbm"; # location of database
my $file = "count.txt"; # location of count file
unlink "chat";
tie %chat, "DB_File", "chat", O_CREAT | O_RDWR, 0644, $DB_HASH
or die "Cannot open file 'fruit': $!\n";
tie %chat, "Tie::IxHash"
or die "Cannot tie %chat to Tie::IxHash : $!\n";
tie %chatorder, "Tie::IxHash"
or die "Cannot tie %chatorder to Tie::IxHash : $!\n";
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) {
my $keeptime = join ( '~', $hour, $min, $sec );
my $info = join ( '~~', $name, $message, $keeptime );
$chat{$cnt} = $info;
}
else {
print "Message was missing, data not sent.
";
}
}
else {
print "Name was missing, data not sent.
";
}
}
foreach ( reverse keys(%chat) ) {
$add++;
if ( $add <= 10 ) {
$chatorder{$_} = $chat{$_};
}
}
foreach ( reverse keys(%chatorder) ) {
my ( $name, $message, $time ) = split /~~/, $chatorder{$_};
$message = wrap( '', '', $message );
print Tr(
td(
{ -width => '700' },
"<$name @ $time>$message"
)
),