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 <db-file> 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 <db-file> 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to