Some questions about your solution and data. Some data from file2:
WILYCO CNW 437106 L 2013,07,08 WILYCO MKT 4399 L 2013,07,03 WILYCO MKT 4559 L 2013,07,23 2013,07,26
What do you want to do when there is not a second date? Also, is it possible to not have a first date? What would you do in that case? Because, your code is (date calculations flawed I think - see next question about the dates):
my @ymd1 = split ',',$dates[4] //= $prev_mth_end; my @ymd2 = split ',',$dates[5] //= $prev_mth_end;
Do you really want to assign $prev_mth_end to both if both are blank?
# work out end of current month my ($y,$m,$d) = Today(); my $mth_end = sprintf "%04d,%02d,%02d",$y,$m,Days_in_Month($y,$m); # ($year,$month,$day) = Add_Delta_Days($year,$month,$day,$Dd); my $prev_mth_end = sprintf "%04d,%02d,%02d", Add_Delta_Days($y,$m,1,-1);
It is August now and your date code is using Today(), but your file 2 data is all for the month of July. I think this might be a problem, as the dates won't pertain to July but instead August.

I don't see where you are taking into account for the days from the previous month (June, file 1).

For example, a record from file 1 shows 2 days:

BIGCO-C  MKT   575 L 6/30/13  2
The corresponding record from file 2 shows:
BIGCO-C   MKT      575 L 2013,07,01 2013,07,02
Subtracting 2013,07,01 from 2013,07,02 = 1 day? Then, total days be 2 + 1 = 3 in this case?

From that, subtracting the 3 free days would give 0 billing days? Are you calculating Demurrage?


In reply to Re: How to use 2 files for calculating charges by Cristoforo
in thread How to use 2 files for calculating charges by rruser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.