in reply to Clean out da hash...
Be aware that each keeps state, so adding or deleting elements
in an each loop is not the greatest of ideas. However, your pattern
of usage seems to be supported, though I wouldn't recommend it.
Quote from perldoc -f each
If you add or delete elements of a hash while you're iterating over it, you may get entries skipped or duplicated, so don't. Exception: It is always safe to delete the item most recently returned by "each()", which means that the following code will work:
while (($key, $value) = each %hash) { print $key, "\n"; delete $hash{$key}; # This is safe }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Clean out da hash...
by davido (Cardinal) on Feb 12, 2004 at 17:02 UTC | |
by GaijinPunch (Pilgrim) on Feb 13, 2004 at 00:19 UTC |
In Section
Seekers of Perl Wisdom