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

Help understanding DB_File and flock

Thread Next
From:
Jay M
Date:
March 18, 2002 15:41
Subject:
Help understanding DB_File and flock
Message ID:
F147X5s7zoMLKmlC7Mz00009720@hotmail.com
Hi,
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 
example.

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

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,
Jay

_________________________________________________________________
Join the worldÂ’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About