I am going to try my best to explain the issue I am confronting. I am pulling a file off of a network drive(directory) in which I must separate, rename by the PO number in the different sections, and then send the different sections with their new names to another directory in which they will be picked up by a fax server to be processed. I am having a little trouble following the replies to the post
How do I split a file into parts. I have been able to make different files in the other directories (sometimes with data, sometimes without), but I can never get the name of the file right. I also need to delete out several "control characters" put into the file by the mainframe when it places it on the network drive. The code that has evolved so far is :
use strict
my $source = "c:/ftproot/$report";
my $fil_count = 0;
my $delim = 'FAX#';
open IN, "c:/ftproot/$report"
or die "Can't open $report: $!\n";
open OUT, ">$filename"
or die "Can't write to $filename: $!\n";
while (<IN>) {
if (/^(.*?)$delim(.*)$/) {
seek (OUT,2,1);
read (OUT, my $num,4);
my $fax = join("",$num,"F",$fil_count,".txt");
my $apollo="c:/reports/$fax";
my $daym=(localtime(time()))[3];
my $afis3="c:/afis3too/$daym/$fax";
print OUT $1 if $1;
foreach my $dest ($truth, $afis3, $apollo,$zenos, $faxarc) {
copy (<IN>, $dest);
}
close OUT;
$fil_count++;
open OUT, "> $filename" . $fil_count . ".txt"
or die "Can't write to out${fil_count}.txt: $!\n";
print OUT $2 if $2;
} else {
print OUT $_;
}
}
close IN;
close OUTPUT;
unlink $source;
I must apologize if this looks messy. I have not even begun to try to tackle the control characters yet. I just want to make sure that I can split the file up and assign the correct filenames to them. Before I forget. The beginning of each segment of the file begins with FAX#, two spaces after that begins 4 bytes that need to be the start of the filename. I hope that helps to clear up a little. Any advice (except to "just give up" 'cause that ain't happenin') would be appreciated. Blacksmith.