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

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to