That will solve the infinite loop problem, but it won't do what you want it to. The basic problem with this code is that neither $CustomerNumber nor $Data{CustomerNumber} are updated within the loop, so *something* will have to change (as written, it's sort of like asking "so, is this number odd?" about the same number over and over instead of (e.g.) "is 5 odd?" the first time, and then "is 6 odd?" the second time)
You're using SQL, which standardly returns sets of results. The standard Perl DBI interface -- which you are not using here -- would have you do something like this:
my $sth = $db->prepare("SELECT foo, bar FROM Cust_ac_da WHERE Customer +ID = ? AND #TranType= 'P'") or die "prepare failed: " . $db->errstr()."\n"; $sth->execute($CustomerNumber); while (my @stuff = $sth->fetchrow() ) { # do things with @stuff } $sth->finish;
here, what happens is that the SQL statment is prepared, then executed (filling in the customer number where the ? occurs in the prepare); when the statement is executed, what happens is a result set is returned, and in this case each call to $sth->fetchrow() returns the next row in that set until there's nothing left in the set. Since you want to go on as long as you're still getting rows data from the database, you should have the test condition be the data-fetching statement.
Things are complicated by the fact that you appear to be using a non-standard interface to your database (at a guess, the person who wrote it designed their own interface on top of DBI). This makes it much harder to recommend how exactly you should go on!
A word of advice : if you're really new to programming and how control structures work, you should really bone up on the basics before you continue. DBI is getting pretty advanced for someone at your stage.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
In reply to Re: Re: Re: Loop Question
by arturo
in thread Loop Question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |