in reply to Re: need help with a bug
in thread Unexpected output from while loop (was: need help with a bug)
When you read F2 and split the fields, you're overwriting some of the variables that you just got from splitting a record in F1. And, as a consequence of reading all of F2 after reading the first record from F1, you're doing all of your calculations based on the first records in F1.
I don't think this is what you want to do.
If you are absolutely sure that the number and order of records will never change, then remove the inner while, so that you're reading a single record from F2 in lock-step with records from F1.
If you can't guarantee that the order or number of records won't change, read each file into an in-memory hash, do the balance math in-memory, and then write the result.
And consider walking through your code line-by-line with a pencil and paper (or with a debugger). It'll help your ability to visualize logic.
|
|---|