Reading about GDBM in this book they only give simple examples of the data structure that can stored. E.g.
$dbm{'key'} = "value";
Background
I would like to save many small text files in the database for local use only, and use nested hashes and arrays to represent the file paths. It doesn't have to be GDBM, but it seams to be the only key/value database library for Perl.
Question
Can I store any hash in GDBM no matter have many nested hashes and arrays it contains?
Does GDBM offer any search features, or I am left to implement my own in Perl?
DBM databases don't support arrays at all. They are esssentially the same as a Perl hash, except that the value of an item can only be a simple string and may not be a number or a reference. The keys and values for each data item in a DBM database are simple byte sequences. That is, the API represents them by a char
pointer and an int
size.
Within that constraint you can use the database however you like, but remember that, unlike SQL databases, every key must be unique.
You could emulate nested hashes by using the data fetched by one access as a key for the next access but, bearing in mind the requirement for unique keys, that's far from ideal.
Alternatively, the value fetched could be the name of another DBM database which you could go on to query further.
A final option is to concatenate all the keys into a single value, so that
$dbm{aa}{bb}{cc}
would actually be implemented as something like
$dbm{aa_bb_cc}