[Chicago-talk] Odd HoH bug/problem

Randal L. Schwartz merlyn at stonehenge.com
Tue Sep 11 12:17:13 PDT 2012

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

Shawn> While I was debugging this I had say Dumper statements, to confirm the
Shawn> data I was expecting was there, to dump the contents of %$types before
Shawn> the while inner loop and everything would work as expected.  W/o it I
Shawn> wouldn't get all my data.  The inputs all stayed the same between each
Shawn> run and I am not doing anything funky w/ the data, just pulling out
Shawn> what I need for output.  I even confirmed after the outer loop that
Shawn> the data I wanted was still there.

Dumper is walking your hashes, resetting your iterators.

There is still something you're not revealing, because I'm puzzled.

I suspect something *before* these loops is leaving the iterators
mid-stride, which is why Dumper "fixes" it.  As a test, try this:

my @dummy = keys %outer;
while (my($k, $v) = each %outer) {
  my @other_dummy = keys %$v;
  while (my($k2, $v2) = each %$v) {

If calling keys like this fixes it, then you have something before the
loop that is leaving the iterator mid-stride.

It's one of the reasons I rarely use each() any more.  That mid-stride
iterator has bit me too many times.

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