sub find_gaps { my $dates = shift; my $ndates = scalar keys %$dates; my @missing = (); return \@missing if $ndates == 0; # Determine the first date in the range my $year = substr((sort keys %$dates)[0],0,4); my $month = 1; while ( ! exists $$dates{ "$year-$month" } ) { do {$month = 1; ++$year} if ++$month > 12; } --$ndates; # Look for gaps until we've seen each date in the range while ( $ndates ) { do { $month = 1; ++$year } if ++$month > 12; if ( exists $$dates{"$year-$month"} ) { --$ndates; } else { push @missing, "$year-$month"; } } return \@missing; }