Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multi Level DBM file

Posted on 2000-02-28
6
Medium Priority
?
219 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Accepted Solution

by:
bitsrfr earned 100 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

604 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