Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Stepping through a hash while modifiying its content

by Anonymous Monk
on Dec 28, 2012 at 05:02 UTC ( #1010618=note: print w/ replies, xml ) Need Help??


in reply to Stepping through a hash while modifiying its content

# Access the hash, and do the deed including any hashkey, value deletions

You should replace that comment with some code :)

You could delay deletion :)

{ my @goners; while( my( $k, $v ) = each %hash ){ push @goners, $k; } delete @hash{ @goners }; undef @goners; }


Comment on Re: Stepping through a hash while modifiying its content
Download Code
Re^2: Stepping through a hash while modifiying its content
by Gorgarian (Initiate) on Dec 28, 2012 at 12:19 UTC

    That is a good suggestion too -- I could run the code in blocks, saving up the deletions, and doing a clean-up after each 1M iterations, then restarting the while loop. I will see how much longer it takes to run after restricting myself to deleting only deleting the most recent iteration reference, and if it is a problem, move to your idea as a Plan B.

    Thanks for your help. Learning ... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010618]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-08-01 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls