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..
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |