Although tie is pretty good for simple hashes, it does not store complex objects. In order to do that you can simply use a FreezeThaw to change between a complex memory structure and a string. So something like this...use NBDM_File; tie %hash, '/some/path/databasefile', 1, 0; $hash{'key'} = 'value'; my $value = $hash{'key'}; untie %hash;
Then, of course, you can get fancy. Like setting up a different hash for each index you want. And in order to keep the data 'synchronized' you can have the index hashes point to an entry ID with a master hash storing each entry ID mapped to a frozen object. Or better yet, even roll your own Perl module that will do all the management of the index databases and the main database for you and just have a simple object oriented interface to work with the information. However at that point you have basically written your own RDBMS and might as well setup MySQL or PostgreSQL.use FreezeThaw qw/freeze thaw/; # Store information my $cdobject = { 'title' => 'My Music', 'author' => 'Me', 'tracks' => [ {'title' => 'songA', 'length' => '1:00'}, {'title' => 'songB', 'length' => '1:50'} ] }; my $cdfrozen = freeze($cdobject); $hash{ $cdobject->{'title'} } = $cdfrozen. # Retrieve information my $cd = thaw( $hash{'My Music'} ); printf "Album %s with %s tracks\n", $cd->{'title'}, $#{$cd->{'tracks'}};
In reply to Re: Perl database
by Anonymous Monk
in thread Perl database
by linex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |