in reply to Re^3: Problem: read a GDBM hash with 2 keys in perl
in thread Problem: read a GDBM hash with 2 keys in perl

Thanks for your time. As I am new to Perl, what about assigning a list as the VALUE in the hash? is it possible or GDBM doesn't support it again?!
key => value Iran => ((1,2),(3,1))
The value was an array (1,2) and I pushed another array to it (3,1) and then store it as the value. This is not multidimensional, so there shouldn't be any issues, right? Cheers, Reza

Replies are listed 'Best First'.
Re^5: Problem: read a GDBM hash with 2 keys in perl
by almut (Canon) on Jun 29, 2010 at 22:56 UTC

    The problem is that the underlying gdbm library stores mere strings as the value of an entry, not Perl data structures. And the Perl module GDBM_File (which is just a thin wrapper around the library) doesn't provide any automatic serialization/deserialization either.

    In other words, you'd have to do that yourself (using Storable, Data::Dumper, whatever) if you want to stick with GDBM.  I.e., convert the Perl data structure into a sequence of bytes (serialization) upon writing, which you'd then have to convert back into a Perl data structure (deserialization) after having read the string from the DB.  Personally, I would rather use another module better suited for the task (like the already mentioned DBM::Deep).