<p>If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys?  I have heard that using <code>each</code> may in some way have unintended side effects.  So, is that true, and is one of the two following methods best, or is there a better way?</p>

<pre><code># Method 1
while (my ($key, $value) = each(%hash)) {
    # Something
}

# Method 2
foreach my $key (keys(%hash)) {
    # Something
}
</code></pre>

I may get bitten by this one but I think that it's personal preference.  I can't find any reference in the docs to each() being different than keys() or values() (other than the obvious "they return different things" answer.  In fact the docs state the use the same iterator and they all return actual list values instead of copies of them, and that modifying the hash while iterating over it using any call is bad.
All that said, I almost always use keys() because to me it is usually more self documenting to access the key's value via the hash itself.  I occasionally use values() when the value is a reference to a large structure and the key to the hash was already stored in the structure, at which point the key is redundant and I don't need it.  I think I've used each() 2 times in 10 years of Perl programming and it was probably the wrong choice both times =)