SPUG: NDBM questions

Benjamin Franks benjamin at dzhan.com
Thu Mar 14 17:30:46 CST 2002


Just to clarify my earlier question....I'm not looking for a perl function
for memcpy, but for a perl equivalent to my example use of memcpy which
uses the cast.  I think "unpack" may be what I want, but can't seem to get
it right...

thanks,
--Ben


On Thu, 14 Mar 2002, Benjamin Franks wrote:

>
> 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;
>
> 	key.dptr="bbb";
> 	key.dsize=strlen(key.dptr);
>
> 	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
> open?
>
> Thanks,
> --Ben
>
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      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
>
>


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