如何在Perl的Data :: Dumper中控制变量名?

如何在Perl的Data :: Dumper中控制变量名?

问题描述:

我有这个简单的Perl脚本:

I've got this simple Perl script:

#! /usr/bin/perl -w

use strict;
use Data::Dumper;

my %foo = ( 'abc' => 1 );

print Dumper(\%foo);

它输出:

$VAR1 = {
          'abc' => 1
        };

我如何使其输出呢?

%foo = (
         'abc' => 1
       );

print Data::Dumper->Dump( [ \%foo ], [ qw(*foo) ] );

扩展语法采用两个arrayrefs:一种用于转储的标量,另一种用于名称.如果名称以*开头,并且对应的标量是arrayref或hashref,则会生成数组或哈希分配.

The extended syntax takes two arrayrefs: one of scalars to dump, and one of names to use. If the name is prefixed by * and the corresponding scalar is an arrayref or hashref, an array or hash assignment is produced.