Well, as I said, I first thought that Marshall's idea of a solution was good, but since I felt that is was probably a bit complicated. I was hoping to make something simpler. As I said, I ended up doing independently something essentially similar (although written differently and using an additional $flag variable, which isn't really necessary, as Marshall has shown).
Trying to simplify (or at least shorten) the code I tried to use a ternary conditional, something along these lines:
But the compiler doesn't like this. Even adding parentheses does not seem to help.push $flag ? @temp : @result, $num;
So that's why I next came to the idea of pushing the values to a variable containing a reference to either the @temp or the @result array, depending on whether we are in a 6..7 range or not. I think this is pretty clean and clear, and quite concise, but using references this way may be beyond the knowledge of a beginner (although the OP uses an array reference).
In reply to Re^4: Ignore a range of numbers ina List
by Laurent_R
in thread Ignore a range of numbers ina List
by pr33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |