johnrcomeau has asked for the wisdom of the Perl Monks concerning the following question:
When I read back the hash with the 'do' command, the $hash{key1}{key2} part is undef. (When you run this, you might see $hash{key2}{key1} lost, depending on the order that Data::Dumper writes the keys.) Is this a known behavior of 'do'? I suppose that the Perl interpreter hasn't executed the first part of the hash when the self-reference is encountered. What's the best way to deal with this issue? Thanks, Johnmy %element = (a => 1, b => 2); my %hash; $hash{key1}{key2} = $hash{key2}{key1} = \%element; warn Data::Dumper->Dump([\%hash], [qw(rh_saved_hash)]); my $file = 'saved.dat'; open SAVE, ">$file" or die "$file: $!\n"; print SAVE Data::Dumper->Dump([\%hash], [qw(rh_saved_hash)]); close SAVE; do $file; warn 'retrieved ', Dumper $::rh_saved_hash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: retrieving persistent variables with Data::Dumper followed by the 'do' command
by LanX (Saint) on Oct 13, 2014 at 01:50 UTC | |
by johnrcomeau (Novice) on Oct 14, 2014 at 03:23 UTC | |
|
Re: retrieving persistent variables with Data::Dumper followed by the 'do' command
by TomDLux (Vicar) on Oct 14, 2014 at 09:42 UTC |