Evernight
asked on
DB_File - flock
This is an attempt to flock a database, a modified version of a snippet of code from the PERL docs at http://www.perl.com/CPAN-local/doc/manual/html/lib/DB_File.html#HINTS_AND_TIPS.
# begin code
use DB_File;
use Fcntl;
# ...
$database = "/home/test/temp.dbm";
$db = tie(%hash, DB_File, $database, O_RDRW|O_CREAT, 0777) || die "Could not tie database!";
$fd = $db->fd;
open(DB_FH, "+<&=$fd") || die "dup ($!)"; # dies here
flock (DB_FH, 1);
# ...
flock (DB_FH, 8);
undef $db;
untie(%hash);
close(DB_FH);
# end code
The error arises from the line: open(DB_FH, "+<&=$fd"). Now, I understand the concept behind "+<&$fd", but why would this open fail when the tie() did not? The script terminates without setting $!.
If anyone can answer this I would really appreciate it. Pardon any typos, its been a long weekend.
Daniel Crowe
Evernight Design
# begin code
use DB_File;
use Fcntl;
# ...
$database = "/home/test/temp.dbm";
$db = tie(%hash, DB_File, $database, O_RDRW|O_CREAT, 0777) || die "Could not tie database!";
$fd = $db->fd;
open(DB_FH, "+<&=$fd") || die "dup ($!)"; # dies here
flock (DB_FH, 1);
# ...
flock (DB_FH, 8);
undef $db;
untie(%hash);
close(DB_FH);
# end code
The error arises from the line: open(DB_FH, "+<&=$fd"). Now, I understand the concept behind "+<&$fd", but why would this open fail when the tie() did not? The script terminates without setting $!.
If anyone can answer this I would really appreciate it. Pardon any typos, its been a long weekend.
Daniel Crowe
Evernight Design
ASKER
I don't think I've ever spent so much time trying to figure out what the leters "dup" stand for. ;p
ASKER
Anyone have any idea? Even a hint or suggestion? Please.
ASKER
Adjusted points to 209
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER