CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
DBM files and multi dimensional hashes

 



EnergyGuy
Deleted

Feb 12, 2000, 2:28 AM

Post #1 of 3 (746 views)
DBM files and multi dimensional hashes Can't Post

As far as I have seen and read, I believe that dbm file can store only a normal hash, and not a multi-dim. hash ( hash of arrays as described in perl by example ).
Am I wrong?


EnergyGuy
Deleted

Feb 24, 2000, 3:05 PM

Post #2 of 3 (746 views)
Re: DBM files and multi dimensional hashes [In reply to] Can't Post

MLDBM is a perl module that supports multi dimensional hashes. I still havn't tried it.
Not long ago, I've built a search engine (commercial) based on dbm hash, values splitted by | | i.e., and the .pag file grows to 8MB per 1000 sites in the db.
I wonder how it is with MLDBM.
And if the situation is different with mySQL. A flat-file would weight 1MB I think.. do you guys think the binary dbm would be searched faster?...


summer
Deleted

Feb 25, 2000, 2:29 PM

Post #3 of 3 (746 views)
Re: DBM files and multi dimensional hashes [In reply to] Can't Post

MLDBM will certainly do the trick. However it isn't difficult to do it yourself.

One way is to use the Storable module:

use Storable qw( freeze thaw ) ;

# You can then store an arbitrary data structure, say a hash (which can contain hashes, arrays etc.):

$data = freeze( \%Hash ) ; # Serialises arbitrary data into a single scalar

# You then store the data in the dbm file as normal, e.g.:

$dbmhash{$Hash{'KEY'}} = $data ;

# And to get the data back:

%orig = %{ thaw( $dbmhash{$Hash{'KEY'} ) } ;


You could also try the Data: umper module.


The most efficient way is likely to be using pack, but that means that your data must be fixed width (except possibly the last field).

Advanced Perl Programming has v. good info on this.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives