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.
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.