in reply to Re: Loop Question
in thread Loop Question
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Loop Question
by arturo (Vicar) on Mar 21, 2001 at 22:00 UTC | |
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:
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 | [reply] [d/l] [select] |
by Anonymous Monk on Mar 21, 2001 at 22:52 UTC | |
| [reply] [d/l] |
by Anonymous Monk on Mar 21, 2001 at 22:32 UTC | |
| [reply] |
by arturo (Vicar) on Mar 21, 2001 at 22:43 UTC | |
The problem is that I don't know how to do that given the database interface you're using. This is par t of the context problem I mentioned in my first post to your original question. It sounds like you're now saying $Data{CustomerNumber} IS somehow updated, say, by the $db->FetchRow call. But that's not something I, or anybody else unfamiliar with the database interface you're using, can tell just from looking at the code you've posted. So the best I can do is say, in the abstract, the steps you need to take. In pseudo-pseudocode, what you want is:
It sounds like your database interface fetches the data "behind the scenes" and stores it in the %Data hash, which makes it extremely difficult to debug this kind of problem from over here. HTH. Philosophy can be made out of anything. Or less -- Jerry A. Fodor | [reply] [d/l] [select] |