cool:

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:

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; }
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 (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; }
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.

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:

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; }
Now I may have overformatted it, but it certainly makes it easier to see what you're doing.

--roboticus


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.