简体   繁体   English

如何获取Perl Data :: Dumper以遵循作为哈希键的引用

[英]How to get Perl Data::Dumper to follow references that are hash keys

Data::Dumper doesn't seem to expand references that are hash keys, and I can't figure out what settings to change to make it do so. Data :: Dumper似乎没有扩展作为哈希键的引用,而且我无法弄清楚要进行哪些更改。 Is this even possible? 这有可能吗?

Example code: 示例代码:

#!/usr/bin/perl
use Data::Dumper;
@array = ('foo', 'bar');
$arf = \@array;
%hash1 = ( 'baz' => $arf );
%hash2 = ( $arf => 'baz' );
print Dumper(@array); print "\n";
print Dumper(%hash1); print "\n";
print Dumper(%hash2);

This outputs: 输出:

$VAR1 = 'foo';
$VAR2 = 'bar';

$VAR1 = 'baz';
$VAR2 = [
          'foo',
          'bar'
        ];

$VAR1 = 'ARRAY(0x8be1b04)';
$VAR2 = 'baz';

But I would like something to get the output: 但是我想要一些东西来获得输出:

$VAR1 = 'foo';
$VAR2 = 'bar';

$VAR1 = 'baz';
$VAR2 = [
          'foo',
          'bar'
        ];

$VAR1 = [
          'foo',
          'bar'
        ];
$VAR2 = 'baz';

Simplistically, change 简单地说,改变

%hash2 = ( $arf => 'baz' );

to

@hash2 = ( $arf => 'baz' );

Of course, then it's no longer a hash, but an array. 当然,它不再是哈希,而是数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM