develooper Front page | perl.beginners | Postings from December 2002

RE: WELCOME to beginners@perl.org

Thread Next
From:
Frank Naude
Date:
December 31, 2002 05:39
Subject:
RE: WELCOME to beginners@perl.org
Message ID:
LCEGKHCDPKCLMDNEGMKPIEMGDFAA.frank@naude.co.za
Hi,

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;
$x1{'A'} = "B";     # PROBLEM IS THIS DATA WILL NEVER BE WRITTEN TO THE DB
$x1{'B'} = "C";
$x1{'C'} = "D";
print "A = $x1{'A'}\n";
closeDB(\%x1);

# Read data back...
my $z2 = openDB;
my %x2 = %$z2;
print "A = $x2{'A'}\n";
closeDB(\%x2);
# EOF

Best regards.

Frank Naude


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About