SPUG: NDBM questions

Benjamin Franks benjamin at dzhan.com
Thu Mar 14 16:47:37 CST 2002

I have a small NDBM database that is normally written to by a C application.
As the keys and values stored in an NDBM database are character strings,
I'm casting ...  something roughly like.

	struct custom_struct {
	  some complex struct stuff;

	datum key, val;
	struct custom_struct aaa;


	val.dptr=(char *) &aaa;
	val.dsize=sizeof(struct custom_struct);

	/* db is pointer to DBM already opened */
	dbm_store(db, key, val, DBM_REPLACE);

Now when I read the data from the database at a later time, I use memcpy
to move from the stored string back to my struct, as in:

	val = dbm_fetch(db, key)
	memcpy((char *) &aaa, val.dptr, val.dsize);
	/* now work on struct aaa */

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?

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


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