Hi all in the monastry -- hope you are not all sworn to silence during the festive season.
I have a small challenge, being fairly new to perl. I wish to step through a hash with
while ( ($key, $value) = each %hash ){ }
but then modify the hash by deleting key,value pairs from the hash after some processing if they meet a certain condition, with the while loop in progress.
I have this nagging worry that modifiying the contents of the hash on the fly will stuff up the orderly progression of the while loop and that some records may be missed.
Can anyone with a deeper knowledge of perl advise on this?
A workaround would be to establish a companion array
@array = keys %hash; foreach $key (@array){ # Access the hash, and do the deed including any hash # key, value deletions. }
but this doubles the memory requirements, and my files are huge. I would like to avoid this if it is not necessary.
Looking forward to hearing from you. My first post.
In reply to Stepping through a hash while modifiying its content by Gorgarian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |