Re^6: Iterating over hash while deleting elements (Best Practice)by LanX (Cardinal)
|on Feb 07, 2020 at 11:52 UTC||Need Help??|
> while (my $key = delete_first %hash)
I don't think a new iterator is the best generic approach.
Because only the loop's body knows if resetting the iterator is appropriate.
for the general case - iterating a hash and occasionally deleting elements in the body, this should always fit
The Rule: reset the iterator if and only if other elements are deleted.
This will never end in an endless loop, because the hash will
°) not sure how costly resetting is in the end.
²) provided it's a finite structure which isn't refilled simultanously