#!/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++; } }