in reply to Re: Re: funny results
in thread funny results: unexpected order reversal

jspindler,

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