Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Problem with dbm hash?!!

by nagalenoj (Friar)
on May 06, 2009 at 13:14 UTC ( #762267=perlquestion: print w/replies, xml ) Need Help??
nagalenoj has asked for the wisdom of the Perl Monks concerning the following question:

when I have a requirement to store big hashes and process it, I use DBM hashes. But, recently I have heard that using DBM hashes is not a good idea. Is it so? Kindly clarify me why it is so.?

Replies are listed 'Best First'.
Re: Problem with dbm hash?!!
by jettero (Monsignor) on May 06, 2009 at 13:17 UTC
    Who says? It probably depends on the problem space, but I'm not personally aware of any problems with using DBM Hashes. If you want to store really huge perl structures consider DBM::Deep -- it's neat, but not really related to DBM as far as I know.

    Also, I just realized I was thinking DB_File hashes, which I use from time to time. Did you mean something else?

    UPDATE: nearly the same thing. In fact, for all we know, dbmopen may just use DB_File... see: AnyDBM_File. Regardless, I think those are just fine for smaller apps. For apps with a lot of concurrency or application interactions, maybe a real database is better. It depends. Few solutions are right for all problems. That's part of the reason there's more than one way to do it.


      Thanks for you reply. Actually, I have not used DB_File.

      I use dbmopen(), dbmclose() like follows,

      #!/usr/bin/perl use strict; use warnings; my %hash; # To open a dbmfile and associate with hash dbmopen(%hash, "nagalenoj", '0666') || die "Can't open database file!" +; $hash{'one'}="1"; $hash{'two'}="2"; $hash{'three'}="3"; #Retrieving values print $hash{'three'}; dbmclose %hash;
Re: Problem with dbm hash?!!
by moritz (Cardinal) on May 06, 2009 at 13:18 UTC
    I don't see what's wrong with it, as long as you want to store flat hashes. dbm doesn't support nested data structures, which could be a pain if you need them.
Re: Problem with dbm hash?!!
by vinoth.ree (Monsignor) on May 06, 2009 at 14:19 UTC

      Hmmm... I wonder if the Applied Research Lab of the Washington University in St. Louis got permission from the copyright holder, O'Reilly & Associates, to host The Perl CD Bookshelf on its website. I doubt it...



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://762267]
Approved by jettero
[choroba]: 1. Learn to link: [id://1209704]Strings/Numbers aren't equating properly
[choroba]: 2. We see new posts in RAT, no need to advertise them here

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-02-22 00:28 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.