Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Cause of an endless loop?

by davidrw (Prior)
on Jun 18, 2005 at 22:15 UTC ( [id://468036]=note: print w/replies, xml ) Need Help??


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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (None)
    As of 2024-04-25 01:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found