Solved

Multi Level DBM file

Posted on 2000-02-28
6
217 Views
Last Modified: 2010-03-05
I am using a multi level data structure in my Perl script, for example:

%hash {};

$hash{name}{family}[age]{sex}

I want to store the data structure in a DBM file. apparently DBM files can store only key, value pairs and not intricate data structures.
I have tried using MLDBM from CPAN but to no avail, either due to my lack of  know-how or to another problem.

Please advise.

Thanks,

Shay
0
Comment
Question by:shayb022800
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:makerp
ID: 2564764
it looks like you may have an eaiser life using a database and using dbi/dbd ?. you will then get all of the benifits of sql etc .
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2565143
What about a text delimited file which can be interfaced with SQL?  The module Sprite has been a favorite of mine for database like work on a small scale.

http://www.perl.com/CPAN-local/modules/by-module/Sprite/

If this sounds appealing I can help with code though the example included is rather good...
0
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2568863
Greetings.

In alternative, you could use composite keys:

$hash{"$name,$family,$age,$sex"}=...

Or even:

$key=join("\007",($name,$family,$age,$sex);
$hash{$key}=...;

If you are doing more complex things, then the suggested DBMS stuff is the way to go.

Cheers,

  alf

 
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
bitsrfr earned 50 total points
ID: 2583326
I am doing exactly what you speak of.  You must use the package MLDBM.  Go down that path - the correct one - and ask questions when you come to problems implementing that.  I will help you...
0
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2587580
It's always nice to get in touch with people which are able, without any uncertainty, to thread  'the correct path'...

0
 

Expert Comment

by:bitsrfr
ID: 2587798
hehe, yes, it is a gift. :-)

Shay,

   Perhaps where you ran into problems with MLDBM is that "Adding or altering substructures to a hash value is not entirely transparent in current perl.  If you want to store a reference or modify an existing reference value in the DBM, it must first be retrieved and stored in a temporary variable for further modifications.  
In particular, something like this will NOT work properly:

$mldb{key}{subkey}[3] = 'stuff';        # won't work

Instead, that must be written as:

$tmp = $mldb{key};                      # retrieve value
$tmp->{subkey}[3] = 'stuff';
$mldb{key} = $tmp# store value
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question