给定以下代码
#!/usr/bin/perl
use Data::Dumper;
my %hash;
my @colos = qw(ac4 ch1 ir2 ird kr3);
foreach my $colo (@colos) {
if(exists $hash{output}{$colo}) {
print "$colo is in the hash\n";
}
}
print Dumper(\%hash);
我有一个空的哈希表,我创建了一个包含一些缩写的数组。如果我循环遍历数组来查看这些缩写是否在哈希表中,那么预期情况下不会在STDOUT中显示任何内容,但是一些原因导致$hash{output}被创建。这没有意义。我只是在做一个if exists。我错在哪里了?