No offense intended, but you should trim down your code before sending a question like that. Many will skip the node if they have to work too hard to see the problem. (See nodes like How (Not) To Ask A Question).
Anyway, on to your question. Based on your statement and the code, I'd imagine that your problem is that you process the data this way:
The $sth2->fetchrow_array() call returns false when it has nothing to report back, and you're assigning that to an array. Move the extra assignment into your loop so it's only copied if you have a row of data:while (($endstore[$ctrend][0],$endstore[$ctrend][1],$endstore[$ctren +d][2],$endstore[$ctrend][3],$endstore[$ctrend][4])= my @arr)= $sth2-> +fetchrow_array() ) { my ($field1, $field2, $field3,$field4,$field5)=@arr; $endflag=2; print STDOUT "Field 1: $field1 Field 2: $field2 Field 3: $field3 F +ield 4:$field4 Field5: $field5\n"; ++$ctrend; }
But you really need to start working on structuring your programs to make them simpler to read. This will help make your code more maintainable, as well as making it easier to steal bits from for other projects.while (my @arr = $sth2->fetchrow_array() ) { # Keep a copy of the data for future use ($endstore[$ctrend][0],$endstore[$ctrend][1],$endstore[$ctrend][2] +,$endstore[$ctrend][3],$endstore[$ctrend][4])= @arr; my ($field1, $field2, $field3,$field4,$field5)=@arr; $endflag=2; print STDOUT "Field 1: $field1 Field 2: $field2 Field 3: $field3 + Field 4:$field4 Field5:$field5\n"; ++$ctrend; }
Use indentation liberally, don't be afraid of blank lines, and use meaningful variable names. I'm not going to take on your entire script, but let's work on this loop for a moment. A little bit of rearranging will make it a little easier to read:
Now I may have overformatted it, but it certainly makes it easier to see what you're doing.while (my @arr = $sth2->fetchrow_array() ) { # Keep a copy of the data for future use ($endstore[$ctrend][0], $endstore[$ctrend][1], $endstore[$ctrend][2], $endstore[$ctrend][3], $endstore[$ctrend][4]) = @arr; my ($field1, $field2, $field3, $field4, $field5) = @arr; $endflag=2; print STDOUT "Field 1: $field1 Field 2: $field2 " . "Field 3: $field3 Field 4: $field4 " . "Field 5: $field5\n"; ++$ctrend; }
In reply to Re: Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
by roboticus
in thread Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
by cool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |