1

Data::Dumper 似乎没有扩展作为哈希键的引用,我无法弄清楚要更改哪些设置才能这样做。这甚至可能吗?

示例代码:

#!/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);

这输出:

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

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

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

但我想要一些东西来获得输出:

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

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

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

1 回答 1

0

简而言之,改变

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

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

当然,那么它不再是哈希,而是数组。

于 2014-09-09T12:25:45.500 回答