#!/usr/bin/perl

use strict;
use DB_File;

sub LOCK_SH { 1 }
sub LOCK_EX { 2 }
sub LOCK_NB { 4 }
sub LOCK_UN { 8 }

my %db_hash;
my $db_obj = tie(%db_hash, "DB_File", "foo01.db", O_CREAT|O_RDWR, 0644)
	or die "dbcreate foo01.db $!";

#$fd = $db_obj->fd;
#print "$$: db fd it $fd\n";
#open(DB_FH, "+<&=$fd") or die "fdopen $!";

my $command = shift;
my $key = shift;
my $value = shift;

if ( $command eq "read" ) {
	my $x = $db_hash{$key};
	print "reading key $key = x\n";
}
elsif ( $command eq "write" ) {
	$db_hash{$key} = $value;
	print "set key $key = $value\n";
}
elsif ( $command eq "list" ) {
	foreach ( sort keys %db_hash ) {
		print "$_ = $db_hash{$_}\n";
	}
}
elsif ( $command eq "bunches" ) {
	foreach ( 1 .. 200 ) {
		$db_hash{$key . $_} = $value;
	}
}
else { die "ack" }


