perl 第三层hash 提取keys 错误%hash = (name => {small => {dog => 1,cat => 2,rabit => 3,},medium => 1,large => 2,},);my @keys = keys %{$hash{name}}; ==> result:large small medium...3.my @keys = keys %{$hash{name{small}}};==> Can't locate object

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/28 01:44:56
perl第三层hash提取keys错误%hash=(name=>{small=>{dog=>1,cat=>2,rabit=>3,},medium=>1,large=>2,},);my@keys=key

perl 第三层hash 提取keys 错误%hash = (name => {small => {dog => 1,cat => 2,rabit => 3,},medium => 1,large => 2,},);my @keys = keys %{$hash{name}}; ==> result:large small medium...3.my @keys = keys %{$hash{name{small}}};==> Can't locate object
perl 第三层hash 提取keys 错误
%hash = (
name => {
small => {
dog => 1,
cat => 2,
rabit => 3,
},
medium => 1,
large => 2,
},
);
my @keys = keys %{$hash{name}}; ==> result:large small medium...3.
my @keys = keys %{$hash{name{small}}};==> Can't locate object method "name" via package "small" (perhaps you forgot to load "small"?) at hash line 20.
my $keys = @keys;
print "@keys...$keys.\n"
为什么无法获取第三层的hash keys,而第二层则正常?

perl 第三层hash 提取keys 错误%hash = (name => {small => {dog => 1,cat => 2,rabit => 3,},medium => 1,large => 2,},);my @keys = keys %{$hash{name}}; ==> result:large small medium...3.my @keys = keys %{$hash{name{small}}};==> Can't locate object
keys %{$hash{name{small}}}需要修改为
keys %{$hash{name}{small}}