From: "Frank Naude" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: RE: WELCOME to [EMAIL PROTECTED]
Date sent: Tue, 31 Dec 2002 15:39:55 +0200
How's this related to the welcome message???
> Can somebody please help me to get this code fixed? Since I've moved
> the DB_File "tie" and "untie" functions to sub's, data is never
> written to the database. I've tried both call-by-refeence and
> call-by-value methods without any luck.
>
> use strict;
> use DB_File;
> sub openDB {
> my %db;
> tie(%db,'DB_File',"db",O_CREAT|O_RDWR,0666);
> return \%db;
> }
> sub closeDB {
> # my $parm = shift;
> my ($parm) = @_;
> my %db = %$parm;
> untie(%db);
> }
> # Write data to DB...
> my $z1 = openDB;
> my %x1 = %$z1;
You've just created a new hash and copied all data from the tied hash
to this new one. But the new one is NOT tied to anything!
You should keep using the reference:
my $z1 = openDB;
$z1->{'A'} = "B";
And the closeDB() has the same problem. It should look like this:
sub closeDB {
# my $parm = shift;
my ($parm) = @_;
untie(%$parm);
}
HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]