in reply to Re^2: find the continuity in the data file
in thread find the continuity in the data file

From the context, I'm assuming your files have two header lines and then one number per line.

use strict; use warnings; for (rangeOver(*DATA, 4)) { print "$_->[0] to $_->[1] = " . ($_->[1] - $_->[0] + 1) . "\n"; } sub rangeOver { my ($fh, $min) = @_; my ($start, $end, @ranges, $i); <$fh>; <$fh>; chomp(@_ = <$fh>); return [] if $#_ < $min - 1; $start = $end = shift; for (@_) { if ($_ == $end + 1) { $end++; next; } push @ranges, [$start, $end] if $end >= $start + $min - 1; $start = $end = $_; } push @ranges, [$start, $end] if $end >= $start + $min - 1; return @ranges; } __DATA__ some header 1 3 4 5 6 8 10 11 12 13 14