Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not satisfying a while loop (probably very obvious)

Status
Not open for further replies.

HughbertD

Technical User
Apr 30, 2007
42
GB
Hi all,

I execute this while loop, and it never stops.

$rownumber is definitely 3.

Code:
my ($rownumber) = $execute->numrows();



# FETCHROW ARRAY


my ($i)=0;

while (my (@results) = $execute->fetchrow() && $i<=$rownumber)
{

      	$sheet1->write(0, $i, $results[0], $format);
     	$sheet1->write(1, $i, $results[1]);
        print $i;
        $i++;

}
 
Okay I just figured this out literally the second I hit submit.

I was trying to hard with my conditions. The first condition, (@results) controls the amount of output. The second condition confuses it I think.

 
Well, look at the logic:

$i <= 3

probably $i never is greater than 3, so the while loop never ends. You should not need that anyway.

Code:
while (my @results = $execute->fetchrow())
{

          $sheet1->write(0, $i, $results[0], $format);
         $sheet1->write(1, $i, $results[1]);

}

That should do it. As soon as fetchrow() no longer returns a value to @results the while loop ends.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top