The return value from the flip-flop operator (in scalar context) actually gives you the info you need to skip the first and last values matched.

When the flip-flop operator in scalar 'flips' (when the left hand side is true), it starts at 1 and counts up until it 'flops' (when the right hand side is true). So, skip to the next element when the return value equals 1.

Also, when the flip-flop operator 'flops', it appends 'E0' to the return value. For example, if it finds five matches in a row, it will return (1, 2, 3, 4, '5E0'). So, you should also skip to the next element when the return value contains an E.

Here's how this might be coded:

foreach (@data){ next unless $check = /start/ .. /stop/; next if $check == '1' or $check =~ /E/; # do stuff }

In reply to Re: flip-flop operator and sequence number by chipmunk
in thread flip-flop operator and sequence number by iakobski

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.