I have two files myresult and annotation. data in the two files appear to be as range but they are not, that\'s why i cant store it in an array and i need to use split operator
You don't need to iterate over both the arrays. If the starting points of the ranges are ascending, you can use the following code:
#!/usr/bin/perl
use warnings;
use strict;
my @result = qw( 4..20 8..12 14..22 22..29 27..29 28..35 40..50 );
my @annot = qw( 1..5 11..13 25..37 45..55 );
my $from = (split /\.\./, $result[0])[0];
my $to = (split /\.\./, $result[-1])[1];
for my $i ($from .. $to) {
print "$i\n" if grep inside($i, $_), @result
and grep inside($i, $_), @annot;
}
sub inside {
my ($i, $range) = @_;
my ($from, $to) = split /\.\./, $range;
return ($from <= $i and $i <= $to)
}