Hashes: Deleting elements while iteratingby knexus (Hermit)
|on Sep 02, 2003 at 20:22 UTC||Need Help??|
knexus has asked for the
wisdom of the Perl Monks concerning the following question:
I looked at previous posts related to this matter, but they were from Nov. 2000 or so and with older versions of Perl (I am using 5.8.0). Plus they really didn't answer my question (although I could have missed something).
So, here goes...
What I am seeing is a difference in behavior depending on how I iterate, when deleting hash elements. In the test code below, using the first foreach seems to work (the elements "appear" to be deleted) but I get errors:
Use of uninitalized value in pattern match (m//) at line 30.
The other two iteration methods work fine without error. The main reason for this post is that I am still very new to perl (just a couple weeks) so I want to understand this behaviour (this may pass in time, when I just need to get it done... but for now ;-)
Note: I just commented out all but the one I wanted to test. Also, don't read too much into the names and comments in the code as it's superficial. :-)
Could this be caused by "buffering" (for lack of knowing a better term) by sort and each?
Thanks for any info/clarification and I gladly accept tips.