简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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