I guess I will throw mine in as well...
Caveat, your response list will have 0 padded months, but that would be easy enough to correct.... Matter of fact I will, just give me a minute... :)
UpdateRemoved 0 padding in response list.
use strict; use Data::Dumper; my @temp = ( [ qw( testthis 2000-4 2000-2 2000-1 2000-12 2001-1 2002-1 +2 1999-12 ) ], # bad [ qw( testthis 1999-1 1999-2 1999-3 1999-4 1999-5 1999-6 +1999-7 1999-8 1999-9 1999-10 1999-11 1999-12 2001-3 ) ], # bad [ qw( 1999-1 1999-2 1999-3 1999-4 1999-5 1999-6 1999-7 19 +99-8 1999-9 1999-10 1999-11 1999-12 2000-1 ) ], # good [ qw( 1998-12 1999-1 ) ], # good [ qw( 2004-1 ) ], # good [ qw( 2004-12 ) ], # good [ qw( 2004-12 2004-11 ) ], # good [ qw( testthis 2004-12 2004-9 2004-11 ) ] ); # bad foreach ( @temp ) { my %dates = map { s/-(\d)$/-0$1/; $_, '' } @$_; if ( exists $dates{ 'testthis' } ) { delete $dates{ 'testthis' }; print Dumper( \%dates ); my ( $missing ) = find_gaps( \%dates ); print Dumper( $missing ), '-' x 20 ,"\n"; } } sub find_gaps { my $dates = shift; my @date_list = sort keys %$dates; my $c_date = shift @date_list; inc_date(\$c_date); my @gaps = map { trap_gap(\$c_date, $_); } @date_list; s/-0(\d)$/-$1/ for @gaps; return \@gaps; } sub inc_date { my $date = shift; my ($y, $d) = split('-', $$date); if ($d == 12) { $y++; $d = 01; } else { $d++; } $d = "0$d" if $d < 10; $$date = "${y}-${d}"; } sub trap_gap { my ($c, $t) = @_; my @res = (); if ($$c eq $t) { inc_date($c); return (); } while ($$c ne $t) { push(@res, $$c); inc_date($c); } inc_date($c); return @res; }

In reply to Re: Finding gaps in date ranges by Sifmole
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.