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


In reply to Re: How to check missing sequence between sequence range ? by ELISHEVA
in thread How to check missing sequence between sequence range ? by bh_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.