Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Basic Database?

by andreychek (Parson)
on Jun 11, 2001 at 18:10 UTC ( #87497=note: print w/ replies, xml ) Need Help??


in reply to Basic Database?

I think what may help is MLDBM. From the README:
This is the README file for MLDBM, the Perl module that can be used to store multidimensional hash structures in tied hashes (including DBM files).

I can't actually check the documentation because <whine> CPAN is down </whine>, but I believe it uses Data::Dumper to store Perl data types in the DB. Good luck!
-Eric


Comment on Re: Basic Database?
Replies are listed 'Best First'.
Re: Re: Basic Database?
by rob_au (Abbot) on Jun 11, 2001 at 18:42 UTC
    Yes, the MLDBM does use Data::Dumper to store complex multi-level data structures. This module is also covered (briefly) in the O'Reilly Programming the Perl DBI Book - It is from this, that the following little example for illustration is drawn.
     
    #!/usr/bin/perl -w # # ch02/mldbmtest: Demonstrates storaging complex data structures in a +DBM # file using MLDBM module. use MLDBM qw ( DB_File Data::Dumper ); use Fcntl; ### Remove the test file in case it exists already ... unlink 'mldbmtest.dat'; tie my %database1, 'MLDBM', 'mldbmtest.dat', O_CREAT | O_RDWR, 0666 or + die "Can't initialise MLDBM file: $!\n"; ### Create some megalith records in the database %database1 = ( 'Avebury' => { name => 'Avebury', mapref => 'SU 103 700', location => 'Wiltshire' }, 'Ring of Brodgar' => { name => 'Ring of Brodgar', mapref => 'HY 294 133', location => 'Orkney' } ); ### Untie and retie to show data is stored in the file untie %database1; tie my %database2, 'MLDBM', 'mldbmtest.dat', O_RDWR, 0666 or die "Can' +t initialise MLDBM file: $!\n"; ### Dump out via Data::Dumper what's been stored ... print Data::Dumper->Dump( [ \%database2 ] ); untie %database2; exit;

     
    Another way which I have stored complex data structures before has been through the Storable module - This wonderful module even allowed me to store user preference hashes for a web site in a cookie!
     
    Ooohhh, Rob no beer function well without!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://87497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (17)
As of 2015-07-28 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls