Restoring Dumped Values

Restoring Dumped Values

am 27.09.2010 00:12:37 von Eric Robertson

This is a multi-part message in MIME format.

--===============1418629955==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0008_01CB5DD0.50276190"

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01CB5DD0.50276190
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

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?





Eric Robertson




------=_NextPart_000_0008_01CB5DD0.50276190
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">


charset=3Dus-ascii">









style=3D'font-size:
10.0pt;font-family:Arial'>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.



style=3D'font-size:
10.0pt;font-family:Arial'> 



style=3D'font-size:
10.0pt;font-family:Arial'>Am I attempting the impossible, or if not how =
should
I set about reconstituting to the original =
hash?

































style=3D'font-size:
10.0pt;font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Eric Robertson

































lang=3DEN-GB
style=3D'font-size:12.0pt'> 









------=_NextPart_000_0008_01CB5DD0.50276190--



--===============1418629955==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

RE: Restoring Dumped Values

am 27.09.2010 03:56:50 von Jeff Saxton

--===============1026110578==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_F8345BDA8C5CED4691D4E5BA8DF75994015D924B3BEXC HANGEVS01b_"

--_000_F8345BDA8C5CED4691D4E5BA8DF75994015D924B3BEXCHANGEVS0 1b_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

just "do" it ;)

________________________________
From: activeperl-bounces@listserv.ActiveState.com [activeperl-bounces@lists=
erv.ActiveState.com] On Behalf Of Eric Robertson [ericrob@blueyonder.co.uk]
Sent: Sunday, September 26, 2010 3:12 PM
To: activeperl@listserv.ActiveState.com
Subject: Restoring Dumped Values

I=92ve 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=92v=
e succeeded with the first part and produced the text file with =91print OU=
T Dumper (%hash)=92 but using eval with the contents of the file doesn=92t =
reproduce the original hash file.

Am I attempting the impossible, or if not how should I set about reconstitu=
ting to the original hash?





Eric Robertson


--_000_F8345BDA8C5CED4691D4E5BA8DF75994015D924B3BEXCHANGEVS0 1b_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable


252">





Tahoma">
just "do" it ;)

=
 




From: activeperl-=
bounces@listserv.ActiveState.com [activeperl-bounces@listserv.ActiveState.c=
om] On Behalf Of Eric Robertson [ericrob@blueyonder.co.uk]

Sent: Sunday, September 26, 2010 3:12 PM

To: activeperl@listserv.ActiveState.com

Subject: Restoring Dumped Values







style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">I=92ve produced a complicate=
d 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=
=92ve succeeded with the first part and produced the text file with =91prin=
t OUT Dumper (%hash)=92 but using eval with the contents of the file doesn=
=92t reproduce the original hash file.


style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">Am I attempting the impossib=
le, or if not how should I set about reconstituting to the original hash? span>

















" style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


-SIZE: 10pt; FONT-FAMILY: Arial"> 


-SIZE: 10pt; FONT-FAMILY: Arial">Eric Robertson

















EN-GB" style=3D"FONT-SIZE: 12pt"> 








--_000_F8345BDA8C5CED4691D4E5BA8DF75994015D924B3BEXCHANGEVS0 1b_--

--===============1026110578==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

Re: Restoring Dumped Values

am 27.09.2010 04:00:39 von Bill Luebkert

On 9/26/2010 3:12 PM, Eric Robertson wrote:
> I=92ve produced a complicated hash that has as its values anonymous hashe=
s and I want to store the hash in a text file and then in another program u=
se this text file to reconstitute the original hash. Using Data::Dumper I=
=92ve succeeded with the first part and produced the text file with =91prin=
t OUT Dumper (%hash)=92 but using eval with the contents of the file doesn=
=92t reproduce the original hash file.
>
> Am I attempting the impossible, or if not how should I set about reconsti=
tuting 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

Re: Restoring Dumped Values

am 27.09.2010 15:29:44 von lyle

On 26/09/2010 23:12, Eric Robertson wrote:
>
> I=92ve 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=92ve succeeded with the first part and produced the text =

> file with =91print OUT Dumper (%hash)=92 but using eval with the contents =

> of the file doesn=92t reproduce the original hash file.
>

Shouldn't that be
print OUT Dumper (\%hash)

Data dumper will name it $VAR1 or something like that. You can get it to =

name it the same as the original, but I think it'll still need to be a =

reference.
Maybe:

Data::Dumper->Dump([\%hash], [qw(hash)]);

Will work (untested). Then if you really didn't want it as a reference:

our ( $hash, %hash );
require "dumpfile.pl";
%hash =3D %$hash;

But that would be silly. Really you should look at data serialization, =

and encode the data structure to YAML or JSON before writing to a file.
That way it could potentially be read in a decoded by any number of =

languages.


Lyle

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

RE: Restoring Dumped Values

am 27.09.2010 20:04:30 von Curtis Leach

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-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@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

RE: Restoring Dumped Values

am 28.09.2010 19:27:56 von Eric Robertson

This is a multi-part message in MIME format.

--===============0491426422==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0003_01CB5F3A.DF01CC50"

This is a multi-part message in MIME format.

------=_NextPart_000_0003_01CB5F3A.DF01CC50
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

An example of the hash is as follows:



$tempHash1{one}=1;

$tempHash1{two}=2;

$tempHash1{three}=3;

$mainHash{first} = \%tempHash1;

$tempHash2{four}=4;

$tempHash2{five}=5;

$tempHash2{six}=6;

$mainHash{second} = \%tempHash2;



I don't know exactly what you mean but I've tried different variations using
eval and do and I still can't get the value back. I'm come to the conclusion
that the value can't be retrieved after using Dumper to dump the value.
Perhaps you can prove me wrong? Bill Luebkert has suggested using Storable
and this works with this type of hash.



Eric



_____

From: Jeff Saxton [mailto:jeff_saxton@bigfix.com]
Sent: 27 September 2010 02:57
To: Eric Robertson; activeperl@listserv.ActiveState.com
Subject: RE: Restoring Dumped Values



just "do" it ;)



_____

From: activeperl-bounces@listserv.ActiveState.com
[activeperl-bounces@listserv.ActiveState.com] On Behalf Of Eric Robertson
[ericrob@blueyonder.co.uk]
Sent: Sunday, September 26, 2010 3:12 PM
To: activeperl@listserv.ActiveState.com
Subject: Restoring Dumped Values

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?





Eric Robertson



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



------=_NextPart_000_0003_01CB5F3A.DF01CC50
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">


charset=3Dus-ascii">










style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>An example of the hash is as =
follows:



style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> 



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash1{one}=3D=
1;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash1{two}=3D=
2;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash1{three}=
=3D3;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$mai nHash{first}
=3D \%tempHash1;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash2{four}=3D=
4;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash2{five}=3D=
5;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$tem pHash2{six}=3D=
6;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>$mai nHash{second}=

=3D \%tempHash2;



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'> =



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>I don’t
know exactly what you mean but I’ve tried different variations =
using eval and
do and I still can’t get the value back. I’m come to the =
conclusion that the
value can’t be retrieved after using Dumper to dump the value. =
Perhaps you can
prove me wrong? Bill Luebkert has suggested using Storable and this =
works with
this type of hash.



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'> =



color=3Dnavy
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial;color:navy'>Eric span>



style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> 



0cm 4.0pt'>



size=3D3
face=3D"Times New Roman"> style=3D'font-size:12.0pt;font-family:"Times New Roman"'>






style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:
size=3D2
face=3DTahoma> Jeff =
Saxton
[mailto:jeff_saxton@bigfix.com]

Sent: 27 September 2010 =
02:57

To: Eric Robertson;
activeperl@listserv.ActiveState.com

Subject: RE: Restoring =
Dumped
Values
style=3D'font-family:"Times New Roman"'>





style=3D'font-size:12.0pt'> 







style=3D'font-size:
10.0pt;font-family:Tahoma;color:black'>just "do" it =
;)







style=3D'font-size:
10.0pt;font-family:Tahoma;color:black'> 
>





size=3D2
color=3Dblack face=3DTahoma> style=3D'font-size:10.0pt;font-family:Tahoma;
color:black'>






color=3Dblack
face=3DTahoma> style=3D'font-size:10.0pt;font-family:Tahoma;color:black;
font-weight:bold'>From:
face=3DTahoma> style=3D'font-size:10.0pt;font-family:Tahoma;color:black'>
activeperl-bounces@listserv.ActiveState.com
[activeperl-bounces@listserv.ActiveState.com] On Behalf Of Eric =
Robertson
[ericrob@blueyonder.co.uk]

Sent: Sunday, September =
26, 2010
3:12 PM

To:
activeperl@listserv.ActiveState.com

Subject: Restoring Dumped =
Values









lang=3DEN-GB
style=3D'font-size:10.0pt;font-family:Arial;color:black'>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.
color=3Dblack>



New"> style=3D'font-size:12.0pt;color:black'>  >

lang=3DEN-GB
style=3D'font-size:10.0pt;font-family:Arial;color:black'>Am I attempting =
the
impossible, or if not how should I set about reconstituting to the =
original
hash?
style=3D'color:black'>

































Roman"> style=3D'font-size:12.0pt;color:black'>  >

Roman"> style=3D'font-size:12.0pt;color:black'>  >

style=3D'font-size:
10.0pt;font-family:Arial;color:black'>Eric Robertson
color=3Dblack>

































New"> style=3D'font-size:12.0pt;color:black'>  >














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


------=_NextPart_000_0003_01CB5F3A.DF01CC50--



--===============0491426422==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

RE: Restoring Dumped Values

am 28.09.2010 19:53:07 von Eric Robertson

> -----Original Message-----
> From: Lyle [mailto:webmaster@cosmicperl.com]
> Sent: 27 September 2010 02:25
> To: Eric Robertson
> Subject: Re: Restoring Dumped Values
>
> On 26/09/2010 23:12, 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.
> >
>
> Shouldn't that be
> print OUT Dumper (\%hash)
>
> Data dumper will name it $VAR1 or something like that. You can get it to
> name it the same as the original, but I think it'll still need to be a
> reference.
> Maybe:
>
> Data::Dumper->Dump([\%hash], [qw(hash)]);
>
> Will work (untested). Then if you really didn't want it as a reference:
>
> our ( $hash, %hash );
> require "dumpfile.pl";
> %hash = %$hash;
>
> But that would be silly. Really you should look at data serialization, and
> encode the data structure to YAML or JSON before writing to a file.
> That way it could potentially be read in a decoded by any number of
> languages.
>
>
> Lyle

Thanks for your comments.

Yes, I should have used a reference - not using one gave me a reasonable
text representation of my hash. It was of the following form:

$tempHash1{one}=1;
$tempHash1{two}=2;
$tempHash1{three}=3;
$mainHash{first} = \%tempHash1;
$tempHash2{four}=4;
$tempHash2{five}=5;
$tempHash2{six}=6;
$mainHash{second} = \%tempHash2;

However storing by reference I still couldn't retrieve the hash so I'm going
to use Storable as Bill Leubkert has suggested.

As regards using YAML or JSON the program I'm working on is in two parts -
picking up data from a set of csv files and then popping these values into a
MySQL database. I've finished the first part and rather than carry on
testing the second part in the same program I'm dealing with this separately
since extracting the data takes about 10 seconds and having to go through
this every time would slow down my debugging of the second part in Komodo.
The idea then was to dump the data at the end of the first program and then
retrieve this to start off the testing of the second one. Eventually the two
programs will be joined together so this is just a temporary arrangement and
no one else will need to read the dumped file, which will be disappearing.
I'm familiar with complicated hashes but have never used JSON (as yet) so
it's much easier for me to use hashes - I haven't come across YAML.

Eric


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

RE: Restoring Dumped Values

am 28.09.2010 19:55:33 von Eric Robertson

> -----Original Message-----
> From: Bill Luebkert [mailto:dbecoll@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.

Eric


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

RE: Restoring Dumped Values

am 28.09.2010 20:11:23 von Eric Robertson

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-bounces@listserv.ActiveState.com
> [mailto:activeperl-bounces@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-bounces@listserv.ActiveState.com
> [mailto:activeperl-bounces@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

RE: Restoring Dumped Values

am 30.09.2010 13:13:43 von Brian Raven

Eric Robertson <> wrote:
>> -----Original Message-----
>> From: Bill Luebkert [mailto:dbecoll@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