in reply to How to check missing sequence between sequence range ?

The first and foremost reason your script is failing is that you are never putting anything into @missing except undefined values. $commseq is never defined nor declared. There are also at least four other undeclared variables in your script @sortlst, @missing, $nextseq, $curseq. I'm guessing therefore you are not using strictures.

It is very important that you include the following two lines at the start of every script and module:

use strict; use warnings;

These two lines will save you a world of trouble by quickly drawing your attention to potential bugs and problems. Had you done that, it would have been immediately clear to you that $commseq was undefined.

I also note that you are using ne to compare numbers. Even though the numbers originally began a strings, Perl can happily convert those strings to numbers. If you want to compare two numbers as numbers (and I assume you do since your sort routine uses <=> ), you should use the numeric operators:  < <= == => > - see perlop for more information.

As for the algorithm itself, if you have large gaps you will be printing out lists of numbers that will be so long as to be unusable. If you want to print out all the missing numbers (not just the places where only one is missing), then you might want to consider modifying your code to print out ranges of missing numbers rather than each number individually, like this:

# if ($curseq ne $nextseq) { # while ($curseq ne $nextseq) { # push(@missing, $commseq); # print ("Found missing file sequence $curseq - $nextseq\n"); # $curseq++; # } # } # $curseq = $nextseq; # } if ($curseq < $nextseq) { my $endseq = $nextseq-1; if ($curseq == $endseq) { push @missing, $curseq; } else { push @missing, "$curseq-$endseq"; } } $curseq = $nextseq; } print "missing=<@missing>\n";

Best, beth

Update added observations other than strictures