I have the following code:
$printline="O*N%1d5TG%5d ,CLS=%.8s,XXX,BAT=,
+ \n";
$dest_mailbox=shift(@ARGV);
$file=shift(@ARGV);
$message_class=shift(@ARGV);
# Set up a temp file as a holding file for valid lines
$rand = int(rand(10000));
$tempfile="$file" . "$rand";
print "!Creating temp file: $tempfile!\n";
while (-f $tempfile) {
$rand = int(rand(10000));
$tempfile="$file" . "$rand";
}
#
# Open the input file and temporary file
#
open (FILE, "$file") or &exit_with_error("!Error opening file for read
+: $file!\n");
open (TEMP, ">>$tempfile") or &exit_with_error("!Error opening file fo
+r write: $tempfile!\n");
#
$total_lines=0;
$hort=0;
** Prints to temp file the header record **
printf TEMP $printline,$hort, $dest_mailbox, $message_class;
** Prints to temp file the data from another file **
while (<FILE>) {
$total_lines++;
chomp($_);
print TEMP "$_\n";
$data_lines++;
}
}
** Prints to TEMP file the trailer record.
$hort=9;
printf TEMP $printline, $hort, $dest_mailbox, $message_class;
The whole idea behind this code is to take a file that has data records and insert header and trailer records. The data moves over just fine, but the header and trailer records have a small square box which should be a new line character but is not. The file needs to have a the data on the next line. For some reason the temp file does not like the \n on the header and trailer record.