rruser has asked for the wisdom of the Perl Monks concerning the following question:
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; } # } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: create separate output files based on name
by roboticus (Chancellor) on Dec 18, 2013 at 18:14 UTC | |
Re: create separate output files based on name
by Laurent_R (Canon) on Dec 18, 2013 at 22:26 UTC | |
Re: create separate output files based on name
by Laurent_R (Canon) on Dec 18, 2013 at 18:47 UTC | |
by rruser (Acolyte) on Dec 18, 2013 at 20:29 UTC | |
Re: create separate output files based on name
by sundialsvc4 (Abbot) on Dec 19, 2013 at 00:56 UTC | |
by Laurent_R (Canon) on Dec 19, 2013 at 07:12 UTC | |
by rruser (Acolyte) on Dec 20, 2013 at 15:00 UTC |
Back to
Seekers of Perl Wisdom