in reply to Finding gaps in date ranges
I am absolutely baffled by MeowChow solutions. What the heck does +pop do?
#!/usr/bin/perl -w use strict; sub find_gaps { my $dates=shift; my @dates=sort map { sprintf "%04d-%02d",split/-/ } keys %$dates; my ($c,$l)=($dates[0],$dates[$#dates]); my @gaps; while ($l cmp $c) { my $r=sprintf("%d-%d",split(/-/,$c)); push @gaps,$r unless defined $dates->{$r}; substr($c,5,2)++; if (substr($c,5,2)==13) { substr($c,5,2)='01'; substr($c,0,4)++; } } \@gaps; } my %dates=map { $_,'' } qw ( 2000-4 2000-2 2000-1 2000-12 2001-1 2002- +12 1999-12 ); my $gaps=find_gaps \%dates; print "dates\n",join("\n",sort keys %dates),"\n"; print "gaps\n",join("\n",@$gaps),"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Finding gaps in date ranges
by MeowChow (Vicar) on May 11, 2001 at 09:11 UTC |