Because you initialise $previous to 0, the results will be incorrect if the lowest number in the list is 1. I'd avoid that problem by using undef to signal that there is no previous value:
Hugomy $previous; ... if (defined($previous) && $previous == $number - 1) { $table{$base}++; } else { ... }
In reply to Re: grouping consecutive integers
by hv
in thread grouping consecutive integers
by oboyle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |