Set $Data::Dumper::Purity to 1:
#!/usr/bin/perl
use Data::Dumper;
$Data::Dumper::Purity = 1;
$old = { name => "bob" };
$young = { name => "bob jr" };
$old->{child} = $young;
$young->{parent} = $old;
$string = Data::Dumper->Dump([$old],[qw(old)]);
undef $old;
undef $young;
eval "$string";
$check = Data::Dumper->Dump([$old],[qw(old)]);
if ($string ne $check) {
print "eek!\n";
}
print "\n---\n$string---\n$check\n";
Data::Dumper's man page says:
The default output of self-referential structures can be `eval'ed, but the nested references to `$VAR'n will be undefined, since a recursive structure cannot be constructed
using one Perl statement. You should set the `Purity' flag to 1 to get additional statements that will correctly fill in these references.
Ciao, Valerio