use strict; use warnings; use Data::Dumper; my %h; my $undef = undef; $h{''}='test2'; $h{$undef} = 'test'; print Dumper (\%h);
创建以下输出:
$VAR1 = { '' => 'test' };
为什么会这样?
我有Perl 5.12.3.
谢谢你的时间.
解决方法
所有哈希键都是字符串.用作散列键的非字符串值被强制转换为字符串,undef在该上下文中变为“”.