sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:
This is a real short snippet of the code I'm using, anyone have suggestions?
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.<br>"; } } else { print "Name was missing, data not sent.<br>"; } } 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' }, "<font color=blue><$name @ $time></font>$message" ) ),
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DB_File, not saving
by sauoq (Abbot) on Jul 17, 2003 at 19:08 UTC | |
by jsprat (Curate) on Jul 17, 2003 at 19:20 UTC | |
by sauoq (Abbot) on Jul 17, 2003 at 19:34 UTC | |
by jsprat (Curate) on Jul 17, 2003 at 20:00 UTC | |
by sauoq (Abbot) on Jul 17, 2003 at 20:15 UTC | |
by sulfericacid (Deacon) on Jul 17, 2003 at 21:47 UTC | |
| |
by sulfericacid (Deacon) on Jul 17, 2003 at 19:20 UTC | |
by sauoq (Abbot) on Jul 17, 2003 at 19:28 UTC | |
by diotalevi (Canon) on Jul 17, 2003 at 22:00 UTC |