Solved

Multi Level DBM file

Posted on 2000-02-28
6
211 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now