如何在Perl的Data :: Dumper中控制变量名? [英] How do I control the variable names in Perl's 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.
这篇关于如何在Perl的Data :: Dumper中控制变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文