Dear monks..

I have list of files with sequence number start from 1 until 9999. The file sequence number will be loop between 1 until 9999 and the file sequence will be restart to 1 after it reach the maximum values (9999).

My problem is i want to check any missing sequence between 1 until 9999. But, i have a problem once the file sequence number reach the maximum values and reset to 1. As example, this is file sequence number:-
9996
9998
9999
0001
0003
0005
so, my program will return 9997,0002 and 0004 for missing file sequence..

Hopefully, somebody could shared some ideas to solved my problem. This is my coding:-

sub check_sequence { my $switch_name = shift; my $tmp = 0; my $archive_dir = $dirlst{$switch_name}; opendir(DIR, "$archive_dir") or die ("Can't open $archive_dir\ +n"); foreach my $infile (readdir(DIR)) { next unless $infile =~ /NOK/; $tmp_seq = (split(/_/, $infile))[2]; ($seqno = substr($tmp_seq,2,4)) =~ s/^0//g; push (@file_lst, $seqno) if $seqno !~ /$tmp/; $tmp = $seqno; print "$seqno\n"; } closedir(DIR); @sortlst = sort { $a <=> $b } @file_lst; $curseq = $sortlst[0]; for (my $i =1; $i < @sortlst; $i++) { $nextseq = $sortlst[$i]; $curseq++; if ($curseq ne $nextseq) { while ($curseq ne $nextseq) { push(@missing, $commseq); print ("Found missing file sequence $c +urseq - $nextseq\n"); $curseq++; } } $curseq = $nextseq; } }

In reply to 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.