in reply to funny results: unexpected order reversal
YuckFoo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: funny results
by jspindler (Initiate) on Feb 21, 2002 at 00:38 UTC | |
| [reply] [d/l] |
by YuckFoo (Abbot) on Feb 21, 2002 at 11:20 UTC | |
I see that $custID, $ccn, ... $amount are all set at the same time, are not changed, then output. Nothing here would account for fields of different records getting mixed up. I don't think this version of the program is responsible for the mix up. A wild guess at the problem: $mastertemp is being opened in append mode. Unless you delete the file before running the program, you are processing results from previous runs of the program. Perhaps an earlier version of the program made the swaps. As was suggested, you already have a hash of $cnn you have seen in %lines. Why iterate over @dupes to find duplicates, just check %lines before writing to DUPES. Some suggestions about your file opening. You are opening MASTERTEMP and DUPES inside the foreach (@dirlisting) loop, reopening them each time you process a file. Not necessary, open them once outside of the loop and only open in append mode if you really need to, otherwise just open for writing. Also very important is to always, always, check the return of the open(). Another goal you should work towards is to quit using global variables. Variables needed by functions should be passed to the functions. You will reap huge benefits by doing this in larger programs in you future. Again, I don't see the fields getting mixed up in this code. Run the program again starting with a new, empty, MASTERTEMP file and see if the problem persists. YuckFoo | [reply] |
by buckaduck (Chaplain) on Feb 21, 2002 at 13:24 UTC | |
One other minor note, on style. Lines like this: ...can be more cleanly written like this: Or even better, you could have used a format. buckaduck | [reply] [d/l] [select] |