Some time ago I was preparing some presentation about Perl and while reading about flip-flop I was wondering how to easily explain how it works. I couldn't. It works in such intuitive way one can tell "get me everything between /start/ and /stop/". But to explain how it does it, you need two pages of paper :) Ok, I exaggerate a little. Anyway, I discovered another useful construction with the same properties: it can be easily described as "take everything between /start/ and (/end/ which is not inside other /start/ .. /end/ block)". Or shorter: "take /start/ .. /end/ block which can include other /start/ .. /end/ blocks", but kids don't try to analyze it at home :) It can be easily extended to two or more levels of nesting. Pity, I didn't discover it before 'beautiful Perl YAPC'... :)
#!perl while(<DATA>) { if(/start/ .. (!(/start/../end/) && /end/)) { print } } __DATA__ a a a start b start c d e end f start g h i end j end k k l

In reply to Beautiful .. operator by grizzley

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.