From owner-freebsd-current Wed Feb 14 8:13:19 2001 Delivered-To: freebsd-current@freebsd.org Received: from ns.sovintel.ru (ns.sovintel.ru [212.44.130.6]) by hub.freebsd.org (Postfix) with ESMTP id 9B80937B503 for ; Wed, 14 Feb 2001 08:13:14 -0800 (PST) Received: from anry (fw-nat.sovintel.net [212.44.130.15]) by ns.sovintel.ru (8.11.2/8.11.2) with ESMTP id f1EGDAf17131 for ; Wed, 14 Feb 2001 19:13:10 +0300 (MSK) Date: Wed, 14 Feb 2001 19:13:14 +0300 (MSK) From: Andrey Rouskol To: freebsd-current@freebsd.org Subject: db interface question Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi All, I'm trying to write a simple perl program to create a .db file, insert some values and delete some. The problem I have is that everything happy during inserting but when I try to remove all key-value pairs sequently from the .db file my program crashes. I've tested it in FreeBSD-2.8, FreeBSD-4.2 and FreeBSD-CURRENT. Here are two programs - one to create .db file and another to delete all elements from it: --dbcreate - create a database with 100 elements #!/usr/bin/perl -w use DB_File ; use Fcntl ; my $dbfile = shift; if( !defined $dbfile) { print STDERR "Usage: $0 to list\n"; exit 1; } $X = tie( %mydb, DB_File, $dbfile, O_RDWR|O_CREAT, 0666, $DB_HASH ); my $key = "a00"; my $val = "b00"; for(my $i=0; $i<100; $i++) { print "$key - $val\n"; $mydb{$key++} = $val++; } undef $X; untie %mydb; exit 0; -- end of dbcreate --- -- dbclear -- removes all elements from the database #!/usr/bin/perl -w use DB_File ; use Fcntl ; my $dbfile = shift; if( !defined $dbfile) { print STDERR "Usage: $0 to list\n"; exit 1; } $X = tie( %mydb, DB_File, $dbfile, O_RDWR, 0666, $DB_HASH ); my $usr = 0; my $pw = 0; my $i = 0; while( ($usr,$pw) = each %mydb) { print "${usr} - ${pw}: deleted\n"; delete $mydb{$usr}; ++$i; } print "$i elements deleted\n"; undef $X; untie %mydb; exit 0; --- end --- Regards, ------------------------------------------------------- Andrey Rouskol Sovintel To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message