Hope this is helpful!

use strict; use warnings; use Date::Calendar::Profiles qw( $Profiles ); use Date::Calendar; sub to_date { my ($d,$m,$y) = split /\//, shift; return [$y,$m,$d]; } sub from_date { my $date = shift; $date =~ s/(\d{4})(\d{2})(\d{2})/$3\/$2\/$1/; return $date; } my $calendar = Date::Calendar->new( $Profiles->{'DE-SN'} ); # first read in the whole file and # record start and end dates for each employee my %dates; # simplified data reading, pls stick to Text::CSV while (<DATA>) { next if /^empl/; chomp; my( $employee_id,$start_date,$end_date,$total_days) = split /, +/; $dates{$employee_id}{$start_date}{'end'} = $end_date; $dates{$employee_id}{$start_date}{'days'} = $total_days; } # now we have all the data # and can process it for my $employid (sort keys %dates) { my $data = $dates{$employid}; for my $startdate (keys %{$data}) { my $enddate = $$data{$startdate}{'end'}; next if $enddate eq 'invalid'; # redundant, see below # find next businessday my $next = from_date( $calendar->add_delta_workdays(to +_date($enddate),1) ); # do we have a record for the next business day ? if( exists $$data{$next} ) { # merge two records $$data{$startdate}{'end'} = $$data{$next}{'end +'}; $$data{$startdate}{'days'} += $$data{$next}{'d +ays'}; $$data{$next}{'end'} = 'invalid'; # mark redun +dant } } } for my $employid (sort keys %dates) { my $data = $dates{$employid}; for my $startdate (keys %{$data}) { my $enddate = $$data{$startdate}{'end'}; next if $enddate eq 'invalid'; print "$employid,$startdate,$enddate,"; print $$data{$startdate}{'days'},"\n"; } } __DATA__ employid, start, stop, total 1234,01/04/2013,05/04/2013,5 1234,08/04/2013,12/04/2013,5 1234,18/04/2013,18/04/2013,1 1234,22/04/2013,22/04/2013,1 1234,23/04/2013,23/04/2013,1 5678,01/01/2013,01/01/2013,1

In reply to Re^3: Date::Calc and comparing across arrays? by hdb
in thread Date::Calc and comparing across arrays? by rcotten

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.