in reply to Re^3: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List

Yes, you're right, the OP did not specify this possibility, so this may or may not be needed. But taking this possibility into account was what made the solutions suggested by other monks slightly more complicated.

Note that you probably don't need to test $flag in the statements where you change its value. For example the loop of your first solution could be simplified as follows:

for (@$aref) { $flag = 1 if $_== 6; push @new, $_ unless $flag; $flag = 0 if $_== 7; }

Replies are listed 'Best First'.
Re^5: Ignore a range of numbers ina List
by AnomalousMonk (Archbishop) on Jun 25, 2017 at 16:47 UTC
    ... the OP did not specify ...

    pr33 offers some further specification examples here. (Sneaking up on a test-driven methodology... :)


    Give a man a fish:  <%-{-{-{-<

Re^5: Ignore a range of numbers ina List
by anonymized user 468275 (Curate) on Jun 25, 2017 at 14:01 UTC
    Yes you are right - guess I didn't check whether that optimisation was possible, I was just wondering why the most obvious approach wasn;t being suggested.

    One world, one people