in reply to Consecutive number checking
The .. (flip-flop) operator is handy for tests like this. In scalar context it first evaluates true when its left hand side becomes true, then remains true until the right hand side becomes true.
The assignment is from a slice of the original @array, with grep selecting which indexes are to appear.my @array = (1,5,6,7,8,55,63,77,89,103,104,105,106,200,215,554); my @runs = @array[ grep { $array[$_+1] == 1+$array[$_] .. $array[$_+1] != 1+$array[$_] } 0..$#array ]; print "@runs",$/;
That gives an array containing only runs, but there are more than one. As an exercise, try to split them up to get an array of arrays, each consecutive.
After Compline,
Zaxo
|
|---|