http://qs1969.pair.com?node_id=468036


in reply to Cause of an endless loop?

a second approach to the one above that refactors it a little bit -- hopefully will make it a little clearer on how the structure is traversed.
while( my ($s, $u_arr) = each %test ){ foreach my $u_idx ( 0..$#$u_arr ){ my $u = $u_arr->[$u_idx]; while( my ($n, $value) = each %$u ){ print "$s $u_idx $n: $value - \n"; } } }
And if you don't care about the index, it can be:
while( my ($s, $u_arr) = each %test ){ foreach my $u ( @$u_arr ){ while( my ($n, $value) = each %$u ){ print "$s $n: $value - \n"; } } }
Also, the naming of the temp variables (e.g. $user instead of $u, etc) in this case can make a huge difference in trying to figure out where you are in the complex data structure (or when you revist this code at a later date).