Solved

Multi Level DBM file

Posted on 2000-02-28
6
210 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

12 Experts available now in Live!

Get 1:1 Help Now