Thanks for the suggestion. I've used DB_File quite a lot so using that would
have been a possibility but unfortunately because it's not a simple hash
that I'm dumping it wouldn't work. I've read that there is a possible way of
getting round this using MLDBM but I've not followed this up as Storable
suggested by Bill Luebkert does what I want.

I still want to have a text file of my hash so I'm still going to use Dumper
for that.

Eric
 

> -----Original Message-----
> From: activeperl-boun...@listserv.activestate.com 
> [mailto:activeperl-boun...@listserv.activestate.com] On 
> Behalf Of Curtis Leach
> Sent: 27 September 2010 19:05
> To: activeperl@listserv.ActiveState.com
> Subject: RE: Restoring Dumped Values
> 
> 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
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.856 / Virus Database: 271.1.1/3160 - Release 
> Date: 09/26/10 08:01:00
> 


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

Reply via email to