in reply to Re^2: OT: clearing a hash
in thread TIMTOWTDI doesn't mean invent an outlandish approach (usually)

Number 1) is safe because in this case, a list of keys will be produced before the deletes are called. For 3) and 4), I though that 'for (keys %hash)' was special cased to iterate over the hash instead of producing a list (just like 'for (@array)' is special cased), but I can't find it in the documentation right now. Anyway, regardless whether it's special cased or not, 3) and 4) are fine as well, due to the exception of modifying a hash while iterating over it by deleting the last element returned by 'each' (since 'keys' and 'values' uses the same iterator).

Abigail

  • Comment on Re: OT: clearing a hash (was: TIMTOWTDI doesn't mean invent an outlandish approach (usually))