Scott, > I am seeking some thoughts on if this is the way I should tackle this > problem. I have two files, both of them tab delimited text files that I > need to combine and then output a new file. > > My idea was to put both files in an array, calling the fields I need, > i.e. $field[0], $field[1] and so on. I need to loop through the entire > file and output on each loop. > > My concern is the overhead by creating the array's. Any thoughts.
A justifiable concern. You don't mention HOW the files are to be combined, so it is reasonable to assume that there is no criteria. It is also assumed that each file is 'complete' in its format (else you might need to insert something specifically 'between' the contents of the two original files to make the data 'flow' as a single file). There is no need to use arrays/cycle through the data twice, at all - such would be an 'overhead'. Take a look at http://www.php.net/manual/en/ref.filesystem.php. Open fileA to write-append Open fileB Read chunk of fileB Write chunk to fileA until have dealt with entire file Close fileA Close fileB The "chunk" bit could be binary and it could be done all in one read, depending upon expected file sizes. If by "new file" you mean that it must be a third file and have a different name to the two input files, then you will need to modify the above, to open a fileC for output, and perform one filecopy for each of files A&B. Regards, =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php