Eric Robertson <> wrote:
>> -----Original Message-----
>> From: Bill Luebkert [mailto:dbec...@roadrunner.com]
>> Sent: 27 September 2010 03:01
>> 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).
>> 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
> 
> Bill
> 
> That's great - Storable works a treat with the kind of hash I have,
> so I'll be using that as a link between the two parts of the programs
> I'm writing.  

Bill's suggestion of Storable is a good one, I have used it to good
effect myself in the past. There are a couple of things you may want to
give consideration to, though. I did have a  problem when I upgraded
Storable and it couldn't the file from the previous version because the
file format had changed. So you need to have good control of which
version(s) of Storable that you are using, and take care when upgrading.
Also, and it may be stating the obvious, the Storable file format is
binary, and a human readable form would have been useful in the
situation described. A human readable format is also useful for
debugging, and can easily be fixed by a bit of hand editing.

I have also had good results using Data::Dumper for the same purpose.
You don't seem to have provided any code, so I can't say what your
problem was, but I am guessing that you used Data::Dumper with no config
settings, which are often required if you intend to eval the output. For
example $Data::Dumper::Purity. (See 'perldoc Data::Dumper' for more).

Then again, I have also written code to produce Data::Dumper-like output
when I wanted more control over the order and format of the output.
Which, not surprisingly for Perl, wasn't that difficult either.

But if Storable does everything you need, then that is probably the
simplest solution to implement.

HTH

-- 
Brian Raven 
 
Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to