in reply to Re: Re: rebuilding hashes
in thread rebuilding hashes
I still don't quite understand why 'four' is being repeated.
It's because you still have a key '4' with a value of "four" that you didn't remove from the hash. Perhaps an illustration. Your hash just after you delete the entry keyed by '2':
0 === zero 1 === one 3 === three 4 === four
Then you loop over the keys creating new entries. After the first iteration of the loop your hash looks like this:
0 === zero # this one reassigned 1 === one 3 === three 4 === four
Second iteration:
0 === zero 1 === one # this one reassigned 3 === three 4 === four
Third iteration:
0 === zero 1 === one 2 === three # this one created 3 === three 4 === four
Fourth iteration:
0 === zero 1 === one 2 === three 3 === four # this one reassigned 4 === four
See?
|
|---|