develooper Front page | perl.beginners | Postings from March 2002

Help understanding DB_File and flock

Thread Next
Jay M
March 18, 2002 15:41
Help understanding DB_File and flock
Message ID:
I am attempting to modify a script that was coded back when perl 4.xx was 
the current version.  This script accesses databases using DB_File and 
dbmopen().  After every dbmopen and dbmclose there is a flock(). For 

dbmopen(%DB, $filename, 0777) || die "Error: $!\n";
#insert code here

Whenever this script run with -w I get "flock on unopened filehandle" 
errors.  Im wondering if the flocks are even neccessary as it appears they 
arn't serving any purpose as they are right now.  What purpose could they 
have served?

Secondly I know that tie is now the way to access these databases and am 
wondering if I could just replace all the dbmopens / flocks with something 
like this instead...

use Fcntl;
use DB_File;
tie %DB, 'DB_File', $filename, O_CREAT|O_RDWR, 0777, $DB_HASH
      or die "Cannot open $filename: $!\n" ;
#insert code here
untie %DB;

Thanks for your help,

Join the worldÂ’s largest e-mail service with MSN Hotmail.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About