Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

DB_File modes

by fionbarr (Friar)
on Feb 10, 2010 at 16:05 UTC ( #822450=perlquestion: print w/replies, xml ) Need Help??
fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

which is better DBMOPEN or tie %hash? All I need for a simple database is DB_File but would like to know which of these usages is better.

Replies are listed 'Best First'.
Re: DB_File modes
by roboticus (Chancellor) on Feb 10, 2010 at 16:55 UTC


    If one way were better in all ways, then we wouldn't need more than one way to do the job. So it depends on how you measure better. But without telling us how you plan to measure "better", there's no way we can give you a reasonable answer. Typical measures are: which is faster for task X? which takes less space when doing Y? which has the simpler API? which provides the most flexibility? etc...


    Update: It's kind of like asking "which is better: butterscotch pudding or watermelon Jello?" There's no way I can tell you which is better for you, but I can tell you that for me, watermelon Jello is the "best". (I can't stand butterscotch pudding.)

Re: DB_File modes
by repellent (Priest) on Feb 10, 2010 at 21:21 UTC
    dbmopen: This function has been largely superseded by the tie function.

    Perhaps this implies that dbmopen is on the verge of deprecation.
Re: DB_File modes
by chuckbutler (Parson) on Feb 11, 2010 at 04:19 UTC

    If you are using a current version of Perl, say > 5.5, using tie %hash is the way to go. Be advised, on some versions/ports tie DOES NOT return the reference to the underlying object of the tie on success. If you are planning to use an extended routine via $ref->routine( ), you may get the reference by $ref = tied(%hash) first. Be sure that the $ref is undef/out-of-scope before you untie %hash. Good luck. -c

      Be advised, on some versions/ports tie DOES NOT return the reference to the underlying object of the tie on success.

      Um, tie always returns the reference to the underlying object, always.

        ...Mostly on non-Unix platforms. You sometimes receive just a 1, true, on success. I have been burned on this a few times, but then again, I work with a lot of non-Unix distributions. Thanks. -c

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://822450]
Approved by sweetblood
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2016-10-21 20:27 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.