http://www.perlmonks.org?node_id=87497


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

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!