SPUG: Re: need help with Class::Methodmaker and tieing hash to DBM

Dan Roscigno roscign1 at roscigno.com
Mon Mar 1 19:29:22 CST 2004


Hey Andrew, when are you giving the debugger talk :)  I bet if I
knew how to use the debugger I could have solved my problem in a
different fashion.

What I ended up doing is remove the datum hash from the args to the
use Methodmaker call and create it by hand and tie it to the
DB_File.  This works fine, but I lose the auto-generated access
functions.

What I would love, is to be able to see exactly what Methodmaker
generates for me, if I could look at that I could figure out the
diff between my manual implementation and Methodmaker's magic
implementation.

Dan Roscigno


On Tue, 2 Mar 2004, Dan Roscigno wrote:

> 
> Here is an update, I have added the code to create the DBM file:
> 
> ##############################################################
> use DB_File;
> use Class::MethodMaker
>         [ new => [qw/ -hash new /],
>         hash => [{      -tie_class => 'DB_File',
>                         -tie_args => [ '/tmp/datum.db',
> 					O_APPEND|O_RDWR, 
> 					0666, $DB_HASH],
>                  }  => 'datum' ],
>         ];
> ##############################################################
> 
> Now I see the file created in /tmp/, and when I store a value in the
> hash 'datum' I can read it back, but the data does not appear to be
> persitent.  On a second run of the code the only value I can see is
> the current data.
> 
> Dan Roscigno
> 
> 
> On Mon, 1 Mar 2004, Dan Roscigno wrote:
> 
> > 
> > Hi All,
> > I am trying to figure out how to tie a hash to a DBM file whie using
> > Class::Methodmaker.  Here is what I think I do:
> > 
> > 1) subclass Tie::Hash with methods that use MLDBM
> > 2) specify the above subclass in the use Class:Methodmaker statement
> > 
> > Is this correct?  If so then what I am looking for is some hand
> > holding with step 1.  I am guessing that I would want to look at the
> > name of the object and the hash that is tied and use that to specify
> > my DBM file.  I have never worked with tie or DBM before, so I am
> > not too sure about this.  If someone could give me a nudge in the
> > correct direction I think I can get started.
> > 
> > Thanks,
> > Dan Roscigno
> > 
> > 
> > 
> > 
> 
> _____________________________________________________________
> Seattle Perl Users Group Mailing List  
> POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org
> 





More information about the spug-list mailing list