use Data::Dumper; use MLDBM qw( DB_File ); use Fcntl qw( :DEFAULT :flock ); sub hash_init2 { #### DBM Configuration ####################### my $dbm_file = "file.db"; my %hash; local *DBM; my $db = tie %hash, 'MLDBM', $dbm_file, O_CREAT | O_RDWR, 0644 or die "Couldn't not tie to $dbm_file: $!"; my $fd = $db->fd; open DBM, "+<&=$fd" or die "Could not dup DBM for lock : $!"; flock DBM, LOCK_EX; undef $db; return \%hash; } my $h = hash_init2(); print Dumper $h;