Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: How to use 2 files for calculating charges

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

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-11-26 00:09 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls