Steve S.
Steve S.

Reputation: 69

Why does Data::Dumper show values that link to other values?

using Data Dumper after parsing some JSON data, I got something like this:

$VAR1 = {
   param1 => 'foo',
   param2 => $VAR1->{param1}
};

Do I get it right, that param2 is a linked to param1 value?

What is this called? Dynamic hash?

Thanks in Advance, Steve

Upvotes: 0

Views: 114

Answers (1)

Ecuador
Ecuador

Reputation: 1177

No need to be confused, the value of param2 is simply a reference that was encountered before in the structure, so Data::Dumper by default shows it as the reference it is. You can set $Data::Dumper::Deepcopy = 1; and have Data::Dumper print the actual values instead if you need it for something. E.g.

my $foo = 'foo';

my $test = {
   param1 => \$foo,
   param2 => \$foo
};

print Dumper($test);

will print out

$VAR1 = {
          'param2' => \'foo',
          'param1' => $VAR1->{'param2'}
        };

But if you start with something like:

use Data::Dumper;
$Data::Dumper::Deepcopy = 1;

Your output will be:

$VAR1 = {
          'param1' => \'foo',
          'param2' => \'foo'
        };

The default behavior is more useful for visual inspection.

Upvotes: 2

Related Questions