Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to use 2 files for calculating charges

by poj (Priest)
on Aug 13, 2013 at 21:40 UTC ( #1049346=note: print w/ replies, xml ) Need Help??


in reply to How to use 2 files for calculating charges

Assuming you can match the records using the number in col 3 then read the values from the previous month into a hash

open PREV,'<','prev.txt' or die "$!"; my %prev_days=(); #BIGCO-C CMO 180304 L 6/30/13 2 while (<PREV>){ chomp; my @f = split /\s+/,$_; $prev_days{$f[2]} = $f[5]; }
and then add them into your $amt calc
while (<$file>) { my @f = split '\s+', $_; $cnt++; # fill empty dates with month end my @ymd1 = split ',',$f[4] //= $prev_mth_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 $pfmt = "%-14s %-5s %-8s %-3s %-12s %-12s %-6s %-6s %-6s %-6s\n"; printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $diff, $ +amt, fmt_curr($cost), $prev; }
poj


Comment on Re: How to use 2 files for calculating charges
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-20 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls