You
NEED to use the extended version of the dumper to do self referencing dump.
#!perl -w
use Data::Dumper;
$Data::Dumper::Purity=1;
$a = { type => 'int' };
$b = \$a->{type};
print "case 1\n", Data::Dumper->Dump([$a, $b], [qw/a b/]);
print "case 2\n", Data::Dumper->Dump([$a, $b], [qw/x y/]);
print "case 3\n", Data::Dumper->Dump([$b, $a], [qw/b a/]);
print "case 4\n", Data::Dumper->Dump([$b, $a]);
This gives you the following output:
case 1
$a = {
'type' => 'int'
};
$b = \$a->{'type'};
case 2
$x = {
'type' => 'int'
};
$y = \$x->{'type'};
case 3
$b = \'int';
$a = {
'type' => ${$b}
};
case 4
$VAR1 = \'int';
$VAR2 = {
'type' => ${$VAR1}
};
In other words, Data::Dumper is smart, but not 'that' smart. In case of dumping variables referencing each other, you have to use the extended Dump and optionally give it the names of your variables so it can distinguish them properly.
Case 3 and 4 are special, they do not match exactly the original input variables. This is caused by the Data::Dumper's parser. The parser maintains a symbolic table of all variables seen, and for every new variable, it will search in the table first. If a match was found, then it would interpret the new variable based on the matching variable in the table. Therefore the ordering of the variables is important, just like defining them in perl script.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.