I believe you can tie a hash directly to a file, hiding all the dirty
work entirely.  This should make it sharable between programs.  But I
can't remember how readable the file is to humans.  It's been a while
since I've done this.

use SDBM_File;
my (%tie_db, %hash);
tie(%tie_db, 'SDBM_File', $file, O_RDONLY, 0666)
   or die "Can't open SDBM_FILE $file: $!\n" ;
%hash = %tie_db;
untie(%tie_db);       # Empties out %tie_db!


For updates, replace "O_RDONLY" with "O_RDWR|O_CREAT"

Just be aware that there is a performance drain as each time the hash
changes the file gets updated while the hash is tied to the file.  If
you are going to have multiple programs update the hash file, you're
going to have to implement a semaphore to lock things so that only one
program can update a file at a time.

Curtis

 
-----Original Message-----
From: activeperl-boun...@listserv.activestate.com
[mailto:activeperl-boun...@listserv.activestate.com] On Behalf Of Bill
Luebkert
Sent: Sunday, September 26, 2010 7:01 PM
To: Eric Robertson
Cc: activeperl@listserv.ActiveState.com
Subject: Re: Restoring Dumped Values

On 9/26/2010 3:12 PM, Eric Robertson wrote:
> I've produced a complicated hash that has as its values anonymous
hashes and I want to store the hash in a text file and then in another
program use this text file to reconstitute the original hash. Using
Data::Dumper I've succeeded with the first part and produced the text
file with 'print OUT Dumper (%hash)' but using eval with the contents of
the file doesn't reproduce the original hash file.
>
> Am I attempting the impossible, or if not how should I set about
reconstituting to the original hash?

Maybe try Storable (store retrieve / freeze thaw).
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to