The idea is still valid though. it just doesn't replace checks after the data entry.
break up the task
- Ensure each new array is internally consecutive
- easiest to do at data entry, when you don't have to think about all the other arrays
- all the arrays together should hold 0 to #, and no number apears more than once.
- after data entry. join the arrays, and sort it, as you are doing now
It adds a step, but doen't add much complexity.
This is assuming that the data is entered within 2 loops, that you can have the the check reset. something like:
my %list;
for my $outer=(1..5){
my $last=0;
for my $inner=(0..9){
my $number=<STDIN>;
unless ($last==0) {
unless ($number==$last+1){
die("bad input");
}
$list{$outer}[$inner]=$number;
}
}
Course its very rough code (and probably won't work without tweaking {or a total rewrite}) the principal is there.