Basically the flip-flop operator has two sides, a left hand and a right hand. The left hand side is evaluated first, and it it returns false, the entire construct returns false. However, when the left side returns true, the entire construct returns true and *keeps* returning true untill the right hand side also returns true, then the entire thing starts to return false again. Heres an example in code:
for(0..10) { if(/2/../5/) { print; } }
On the first iteration, it checks /2/ against $_, which contains 0, so it returns false and nothing is printed. On the second iteration, same thing, except $_ contains 1. On the third iteration however, $_ contains 2 so /2/ matches and the construct returns true and it prints. It keeps printing numbers untill $_ matches /5/.

The more verbose form of this code would look like:
my $flag; for(0..10) { if(/2/) { $flag = 1; } print if $flag; if(/5/) { $flag = 0; } }
Note that the check to set $flag to 0 is *after* the print statement. This is because the construct returns true the first time the right hand side also returns true. It of course returns false after that.

For the rest of my original code, as hofmator explains below, (/foo/../bar/) returns a string, not just a boolean value, and that string has "E0" appended to it when the right hand returns true (thus meaning it's the last value the flip-flop will return true for).

In reply to Re: Re: Re: Re: regex issue by BUU
in thread regex issue by Anonymous Monk

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.