This sort of thing?

#!/usr/bin/perl use strict; my @temp = qw(2000-4 2000-2 2000-1 2000-12 2001-1 2002-12 1999-12); my @dates = (sort { my @a_date = split '-', $a; my @b_date = split '-', $b; $a_date[0] <=> $b_date[0] || $a_date[1] <=> $b_date[1]; } @temp); my @start_date = split '-', shift @dates; my @end_date = split '-', pop @dates; # use mod 12 to make job easy my $start_count = $start_date[0]*12 + $start_date[1]-1; my $end_count = $end_date[0]*12 + $end_date[1]-1; # hash of dates in this time my %date_hash; # build hash for ($start_count..$end_count) { # here's the sneaky trick :) my $year = int($_/12); my $month = $_%12 + 1; $date_hash{$year}{$month}++; } # now delete elements that exist for (@temp) { /(\d+)-(\d+)/; delete $date_hash{$1}{$2}; } # print missing print "Missing dates are\n\n"; my $count=1; foreach my $year (sort {$a <=> $b} keys %date_hash) { for (sort {$a <=> $b} keys %{$date_hash{$year}}) { printf("%4d-%2d ",$year,$_); print "\n" unless $count%4; $count++; } }
cLive ;-)

In reply to Re: Finding gaps in date ranges by cLive ;-)
in thread Finding gaps in date ranges by Ovid

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.