我一直将我的哈希值打印为# of bucket/# allocated。如何打印散列的内容?
不使用while
循环将是最好的(例如,one-liner将是最好的)。
发布于 2009-07-21 23:27:12
Data::Dumper是你的朋友。
use Data::Dumper;
my %hash = ('abc' => 123, 'def' => [4,5,6]);
print Dumper(\%hash);
将输出
$VAR1 = {
'def' => [
4,
5,
6
],
'abc' => 123
};
发布于 2009-07-21 23:25:26
简单:
print "$_ $h{$_}\n" for (keys %h);
优雅,但实际上慢了30% (!):
while (my ($k,$v)=each %h){print "$k $v\n"}
发布于 2012-03-15 14:49:03
下面是不使用Data::Dumper
进行打印的方法
print "@{[%hash]}";
https://stackoverflow.com/questions/1162245
复制相似问题