use warnings; use strict; use constant kMaxGap => 7; my @gappyData; /^(\d+)\s+(\d+)/ and $2 != 0 and $gappyData[$1] = $2 while ; my $lastx; my $lasty; my $currx = 1; for (@gappyData[1..$#gappyData]) { next if ! defined $lastx; next if ! defined $lasty; my $gap = $lastx - $currx - 1; next if $gap == 1; next if $gap > kMaxGap; next if ! defined $gappyData[$currx] or $gappyData[$currx] != $lasty; $_ = $lasty for @gappyData[$lastx .. $currx]; } continue { $lasty = $_, $lastx = $currx if defined $_; ++$currx; } $currx = 1; for (@gappyData[1..$#gappyData]) { if (defined $_) { print "$currx, $_\n"; } else { print "$currx, -\n"; } ++$currx; }