[Chicago-talk] Odd HoH bug/problem

Randal L. Schwartz merlyn at stonehenge.com
Tue Sep 11 11:53:19 PDT 2012

>>>>> "Shawn" == Shawn Carroll <shawn.c.carroll at gmail.com> writes:

Shawn> I hit send to soon...
Shawn> On Tue, Sep 11, 2012 at 1:33 PM, Shawn Carroll
Shawn> <shawn.c.carroll at gmail.com> wrote:
>> Let me preface this by saying that I have not been able to reproduce
>> this problem in a smaller program and I understand that this makes it
>> less useful for identifying the root cause.
>> In my program I create a HoHoH and need to step through in a final
>> sub.  As I've done many times in the past I use a while block and use
>> each to assign the key & value to loop variables.
>> while( my ($id, $types) =  each %data )
>> {
>> say "$id => $types";
>> while ( my ($type, $data) = each %{ $types })
>> {
Shawn>                        say $type
Shawn>                        # processData
Shawn>                   }
Shawn>            }

Shawn> The first say confirms that every $types is a hash but the second
Shawn> while loop doesn't process every $types.  If I replace the second
Shawn> while with a foreach my $type (keys %{$types}) loop everything works
Shawn> as expected.

Are you adding or deleting things from %$types during the each
iteration?  If so, that can mess up your day.

Is anything else also walking the hash (like something calling keys,
values, or each as well)?  There's only one each-style iterator per

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

More information about the Chicago-talk mailing list