Okay, I figured it out. In my original code snippet, I was creating (what I thought) was a unique file name using the date. But because I was only going down to the second, and the script was running so quickly on test data, it thought it should "append" to the existing file. I redid the naming convention for the outbox file to add the original name of the input file, thereby creating a unique output file after each pass of the foreach loop. The final test code below:
########Test Variables
$outbox = "G:\\outbox\\";
$inbox = "G:\\inbox\\";
$archive = "G:\\archive\\";
$log = "G:\\samslog.txt";
####################get the names of all .dat files in inbox directory
opendir(DIR,$inbox);
@files = grep(/\.TAB$/,readdir(DIR));
closedir(DIR);
################
## loop through the TAB files###
foreach $file (@files) {
##Open the .TAB file for reading
open(TAB_FILE, $inbox.$file) || die "Can't open file: $!";
#create file name
$verifile = $outbox.$file."_FIXED.TAB";
#print column headings in output file
open(OUTPUT_FILE, ">>$verifile")||die "Can't open file: $!";
print OUTPUT_FILE "Column1 Column2 Column3\n";
##Loop through each line of the file (1 part number per line)
while (<TAB_FILE>){
##Use chomp to get rid of carriage returns and spaces
chomp;
($column1, $column2, $column3) = split("\t");
print OUTPUT_FILE $column1."\t".$column2."\t".$column3."\n";
close TAB_FILE;
close OUTPUT_FILE;
}# end for each file
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.