SPUG: NDBM questions

Benjamin Turner bjturner at mac.com
Thu Mar 14 18:19:51 CST 2002


On Thursday, March 14, 2002, at 02:47  PM, Benjamin Franks wrote:
> Ok, now for the question.  I'm writing a Perl application that 
> reads from
> the same database.  However, if I tie a %hash to the ndbm file and then
> print out the keys and values, the values are garbled.  Is there a Perl
> equivalent to the C memcpy for byte string copies?

	You'll need to use perl's 'unpack' function to translate 
from these C structures into something perlish. perldoc -f 
unpack will give you the lowdown, though there's a lot there and 
it'll probably take some fiddling. You may wish to separate the 
unpack part of the problem from the ndbm stuff and focus first 
on just unpacking the C structure from a flat file into perl.

> One more question.  Let's say I open a handle to this database 
> (or a file
> in general) in a parent and fork off children.  The children 
> inherit the
> open handle.  Now, if the children close the handle explicitly, 
> does that
> mean it closed for the parent as well?  Or will the parent 
> handle remain
> open?

	The children have their own *copies* of the file 
descriptors, and when they close their *copies*, the parents' 
file descriptors are not affected. In other words, the parent's 
handle will still remain open.

--
Benjamin John Turner          |  bjturner at bigfoot.com
http://www.usfca.edu/turner/  |  bjturner at mac.com

"The happiest of people don't necessarily have the best of 
everything; they just make the most of everything that comes 
along their way."


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list