I am currently processing a file that contains multiple companies and when complete I am manually splitting out based on Company name $f[0]. It would be a great timesaver if I could create a separate output file based on the Company name field $f[0]. Something like COMPANY-A.TXT, COMPANY-B.TXT, etc.
Thanks Perl Monks I appreciate your time and help
sample of company data: COMPANY-A, COMPANY-B, COMPANY-C, etc.
while (<$file>) {
my @f = split '\s+', $_;
# if ($f[0] =~ (/COMPANY-A/)) { # this is just for 1 company
+and not efficient normally i remark this out
if ( $f[0] =~ (/-C$/)) { # this process carryover records
my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty
+dates with previous month end
my @ymd2 = split ',',$f[5] //= $prev_mth_end;
my $diff = Delta_Days(@ymd1, @ymd2) +1; # total days
my $prev = $prev_days{$f[2]} //= 0;
my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0; # d
+ays to be charged
my $cost = ($amt) * 100;
my $free = $diff - $amt;
my $stg_chg = "N/A"; #static field
my $sw_chg = "N/A"; #static filed
my $waive = " ";
my $cartot = ($cost + $stg_chg + $sw_chg);
my $comment = "Carry over from last month";
my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s
+ %-12s %-12s %-12s %-8s %-12s %-40s\n";
printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]),
+ $diff, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt
+_curr($cartot), $comment;
}
#process non-carryover records
else {
my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty dat
+es with previous month end
my @ymd2 = split ',',$f[5] //= $prev_mth_end;
my $diff = Delta_Days(@ymd1, @ymd2);
my $prev = $prev_days{$f[2]} //= 0;
my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0;
my $cost = ($amt * 100);
my $free = $diff - $amt;
my $stg_chg = "N/A"; #static field
my $sw_chg = "N/A"; #static field
my $waive = "";
my $cartot = ($cost + $stg_chg + $sw_chg);
my $comment = " ";
my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s %-
+12s %-12s %-12s %-8s %-12s %-22s\n";
printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $d
+iff, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt_cu
+rr($cartot), $comment;
}
# }
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.