in reply to Re^3: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Ignore a range of numbers ina List
by choroba (Cardinal) on Jun 25, 2017 at 23:05 UTC | |
by Laurent_R (Canon) on Jun 26, 2017 at 06:11 UTC | |
by AnomalousMonk (Archbishop) on Jun 26, 2017 at 13:17 UTC | |
by Laurent_R (Canon) on Jun 26, 2017 at 18:51 UTC | |
by AnomalousMonk (Archbishop) on Jun 26, 2017 at 22:18 UTC | |
|