The studies that I've read say that the number of characters of indentation between levels should be either 3 or 4, 2 is too few and 5 or more is too many. In practice, I have found this to be good advice.$FREQUENCY_QUERY->execute( ); while ( ($FREQUENCY_ID) = @FREQUENCY_QUERY = $FREQUENCY_QUERY- +>fetchrow_array() ) { $FREQUENCY_ID = "$FREQUENCY_QUERY[0]"; $FREQUENCY = "$FREQUENCY_QUERY[1]"; $CHANNEL_QUERY->execute( ); ### better ### $FREQUENCY_QUERY->execute( ); while ( ($FREQUENCY_ID) = @FREQUENCY_QUERY = $FREQUENCY_QUERY->fetchro +w_array() ) { $FREQUENCY_ID = "$FREQUENCY_QUERY[0]"; $FREQUENCY = "$FREQUENCY_QUERY[1]"; $CHANNEL_QUERY->execute( ); .... }
You claim that use strict; and use warnings; are being used. In the case of strictures, one of the purposes is to limit the visibility of variables to just where you need it. If there is some huge block that pre-declares things like $FREQUENCY_ID and gives it scope that makes it visible in all other code, it defeats the whole purpose.
I would expect to see code like this:
I don't think that your foreach() loops do what you want. If you replace "foreach" with "while", what happens will be very different, so it is not clear at all to me what you are saying works and what doesn't. See if you can replicate the problem with a much more simple example.$FREQUENCY_QUERY->execute( ); while ( my ($FREQUENCY_ID, $FREQUENCY) = $FREQUENCY_QUERY->fetchrow_ar +ray() ) { $CHANNEL_QUERY->execute( ); .... } ####### #note # $FREQUENCY_ID = "$FREQUENCY_QUERY[0]"; #not needed, delete # $FREQUENCY = "$FREQUENCY_QUERY[1]"; #not needed, delete #
In reply to Re: Nested While Loops, foreach and next
by Marshall
in thread Nested While Loops, foreach and next
by Chipwiz_Ben
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |