use strict; use DB_File::Lock; use Fcntl qw(O_RDWR O_CREAT); my $r = shift; $r->send_http_header("text/plain"); my $dbfile = "/tmp/foo.db"; tie my %dbm, 'DB_File::Lock', $dbfile, O_RDWR|O_CREAT, 0600, $DB_HASH, 'write'; # assign a random value $dbm{foo} = ('a'..'z')[int rand(26)]; untie %dbm; # read the assigned value tie %dbm, 'DB_File::Lock', $dbfile, O_RDWR|O_CREAT, 0600, $DB_HASH, 'read'; my $foo = exists $dbm{foo} ? $dbm{foo} : 'undefined'; untie %dbm; print "The value of foo: [$foo]";