Solved

DB_File - flock

Posted on 1998-11-01
5
187 Views
Last Modified: 2010-03-04
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
0
Comment
Question by:Evernight
  • 4
5 Comments
 

Author Comment

by:Evernight
ID: 1205859
Adjusted points to 150
0
 

Author Comment

by:Evernight
ID: 1205860
I don't think I've ever spent so much time trying to figure out what the leters "dup" stand for. ;p
0
 

Author Comment

by:Evernight
ID: 1205861
Anyone have any idea?  Even a hint or suggestion?  Please.
0
 

Author Comment

by:Evernight
ID: 1205862
Adjusted points to 209
0
 

Accepted Solution

by:
Igloo earned 200 total points
ID: 1205863
Try RDWR intead of RDRW ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question