An even simpler way to do this would be to add all of the numbers up. This also has the performance benefit of avoiding the sort entirely.
For example:-
my $total = 0; my $expect = 0; for(int i=0;i<@array;i++) { $total += $array[$i]; $expect += $i; Correction: $expect += $i + 1; } return 1 if ($total == $expect);
Aaarrrggghhh - sorry, ignore this post. As has been pointed out, it doesn't work.
In reply to Re: Validate array of numbers in sequence
by dtr
in thread Validate array of numbers in sequence
by AcidHawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |