Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-06-25 19:34 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (569 votes). Check out past polls.