Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: How to use 2 files for calculating charges

by poj (Prior)
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; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049346]
[thezip]: I don't intend on doing any offline development in the Czech Republic soon, so i think I'm safe!
[thezip]: :-)
[choroba]: Yeah, there are countries with wifi everywhere
[choroba]: also, I didn't have a smart phone at that time

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2017-03-23 21:08 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (294 votes). Check out past polls.