Solved

Multi Level DBM file

Posted on 2000-02-28
6
216 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
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Existing perl code to be changed for ftp to sftp handling 14 240
Perl Sort Question 4 141
html form to write data to csv 24 168
Create an automated page index 9 82
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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

733 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