Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何选择Data::Dumper中的引用 让我们考虑这个例子: #!/usr/bin/env perl use strict; use Data::Dumper; my $node = node(undef, undef, 'root'); my $root = $node; $node = node($root, $node, 'tom'); push $root->{children}, $node; $node = node($root, $node, 'clarence'); push $root->{children}, $node; Data::Dumper::Purity; #$root->{children}[0]->{younger} = $root->{children}[1]; print Dumper $root; sub node { return { parent => shift, prev => shift, name => shift, children => [], }; }_Perl_Hash - Fatal编程技术网

如何选择Data::Dumper中的引用 让我们考虑这个例子: #!/usr/bin/env perl use strict; use Data::Dumper; my $node = node(undef, undef, 'root'); my $root = $node; $node = node($root, $node, 'tom'); push $root->{children}, $node; $node = node($root, $node, 'clarence'); push $root->{children}, $node; Data::Dumper::Purity; #$root->{children}[0]->{younger} = $root->{children}[1]; print Dumper $root; sub node { return { parent => shift, prev => shift, name => shift, children => [], }; }

如何选择Data::Dumper中的引用 让我们考虑这个例子: #!/usr/bin/env perl use strict; use Data::Dumper; my $node = node(undef, undef, 'root'); my $root = $node; $node = node($root, $node, 'tom'); push $root->{children}, $node; $node = node($root, $node, 'clarence'); push $root->{children}, $node; Data::Dumper::Purity; #$root->{children}[0]->{younger} = $root->{children}[1]; print Dumper $root; sub node { return { parent => shift, prev => shift, name => shift, children => [], }; },perl,hash,Perl,Hash,这将产生以下输出: $VAR1 = { 'parent' => undef, 'prev' => undef, 'name' => 'root', 'children' => [ { 'parent' => $VAR1, 'p

这将产生以下输出:

$VAR1 = {
          'parent' => undef,
          'prev' => undef,
          'name' => 'root',
          'children' => [
                          {
                            'parent' => $VAR1,
                            'prev' => $VAR1,
                            'name' => 'tom',
                            'children' => []
                          },
                          {
                            'parent' => $VAR1,
                            'prev' => $VAR1->{'children'}[0],
                            'name' => 'clarence',
                            'children' => []
                          }
                        ]
        };
我们可以清楚地看到
root
有两个孩子,分别是
tom
clarence
tom
上的
clarence
的引用非常清楚
$VAR1->{'children'}[0]

但是,如果我使用
$root->{children}[0]->{younger}=$root->{children}[1]在
tom
上添加对
clarence
的引用,输出出错:

$VAR1 = {
          'parent' => undef,
          'prev' => undef,
          'name' => 'root',
          'children' => [
                          {
                            'parent' => $VAR1,
                            'prev' => $VAR1,
                            'younger' => {
                                           'parent' => $VAR1,
                                           'prev' => $VAR1->{'children'}[0],
                                           'name' => 'clarence',
                                           'children' => []
                                         },
                            'name' => 'tom',
                            'children' => []
                          },
                          $VAR1->{'children'}[0]{'younger'}
                        ]
        };

是否有可能约束<代码>数据::翻转器< /代码>或其他任何翻转器总是考虑一些关键字作为参考,以便正确地显示树?

没有很多可以做的,因为<代码>数据::翻转器< /Case>扫描结构深度优先,但我建议您使用

$Data::Dumper::Deepcopy = 1
这将在输出中复制哈希值,而不是插入交叉引用。这就是结果

$VAR1 = {
          'prev' => undef,
          'children' => [
                          {
                            'parent' => $VAR1,
                            'name' => 'tom',
                            'younger' => {
                                           'children' => [],
                                           'prev' => $VAR1->{'children'}[0],
                                           'name' => 'clarence',
                                           'parent' => $VAR1
                                         },
                            'prev' => $VAR1,
                            'children' => []
                          },
                          {
                            'children' => [],
                            'prev' => {
                                        'parent' => $VAR1,
                                        'name' => 'tom',
                                        'younger' => $VAR1->{'children'}[1],
                                        'prev' => $VAR1,
                                        'children' => []
                                      },
                            'name' => 'clarence',
                            'parent' => $VAR1
                          }
                        ],
          'parent' => undef,
          'name' => 'root'
        };