Let me see if I can rephrase the problem:
- You want to create a single output csv file, based on a set of distinct csv input files.
- For each input file, you are going to run your script once, and this will append data to the common output file
- (Or, for each input file, you will do one iteration of a loop in your script to append to the output file? This seems like a reasonable approach.)
- You need to make sure that the line containing the "csv header" (listing of column names) is written only once, at the very beginning of the output file.
If that's a fair description of the problem, then you could use the following logic (expressed here in pseudocode):
open a given input file
open the output file
read first line of input (this will be the csv header)
look at the size of the output file
if output file size is zero, write the csv header to output
loop through remaining lines of input file
write lines to output when appropriate
But if I've drawn the wrong conclusion about what you're trying to do, please clarify.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.