如果我有一堆(键,值)对的Perl哈希,迭代所有键的首选方法是什么?我听说使用each可能会以某种方式产生意想不到的副作用.那么,这是真的,并且是以下两种方法中最好的方法之一,还是有更好的方法?
# Method 1
while (my ($key, $value) = each(%hash)) {
# Something
}
# Method 2
foreach my $key (keys(%hash)) {
# Something
}
Run Code Online (Sandbox Code Playgroud)