in reply to Re: flip-flop operator and sequence number
in thread flip-flop operator and sequence number

.. not being able to do, reduced to nitpicking. Sorry your answer was so beautiful I studied it but.. perl -e '@data=qw(1 2 3 4 5 6 7 8 9 10 11); foreach (grep {not (/1/../3/) =~ /^1?$|E/ } @data) { print "o> $_\n"; } '
prints
o> 2
o> 11

I hope I'm wrong..

Replies are listed 'Best First'.
Re: Re: Re: flip-flop operator and sequence number
by davorg (Chancellor) on Jun 28, 2001 at 19:08 UTC

    Thats looks like the correct output to me. What were you expecting to see?

    Update: Ok. Getting downvotes, so perhaps I'll be a little clearer.

    Your array contains the numbers from 1 to 11. Your flip-flop condition is /1/ .. /3/. These are regular expressions and match if the values they are matched against contain this string in any position. Obviously it switches on when it gets to 1 and switches off when it gets to three. It then switches on again when it gets to 10. It would have switched off again had your array gone up to 13.

    The problem is therefore not with merlyn's algorithm, but with your implementation of it :)

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>