Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBM_File, database not storing data

Status
Not open for further replies.

sulfericacid

Programmer
Aug 15, 2001
244
0
0
US
For some reason I can't get my database to store information anymore. Mind I was originally using SDBM which worked for the most part, ever since I switched over I can't get it to save anything.

I asked this question to someone and their answer was "After you tie %chat to DB_File you re-tie it to Tie::IxHash. (So, you never really use DB_File at all.)". If this is the reason, can someone explain how to fix this?


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 &quot;Message was missing, data not sent.<br>&quot;;
}
}
else {
print &quot;Name was missing, data not sent.<br>&quot;;
}
}



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' },
&quot;<font color=blue><$name @ $time></font>$message&quot;
)
),





&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top