为什么第二次调用 printHash 时哈希为空?
my %hash = ();
addToHash(\%hash);
printHash(\%hash);
sub addToHash {
my %hash = %{$_[0]};
$hash{"test"} = "test";
printHash(\%hash);
}
sub printHash {
print "printHash: \n";
my %hash = %{$_[0]};
foreach my $key (keys %hash) {
print "key: $key, value: $hash{$key}\n";
}
}
输出:
打印哈希:
键:测试,值:测试
打印哈希: