First, I would suggest reading this: Flipin good, or a total flop?, an excellent node by GrandFather.

As to what you hope to save, there isn't anything that just magically skips a bunch of input lines from the file. Each line has to be read sequentially from the input and this I/O operation is typically the resource intensive "expensive" part. The range operation has a "flip/flop" state that says whether you are within the range or not.

Its not clear to me how you decide what is "cool data" or not? or maybe more to the point how you know all the "cool" data has happened and no more is left in that block?

It could be that you need a different "END" regex? Any valid regex can go there, maybe you need to "end" on either START or END tokens? Or have some term that factors in "all cool data processed"? That would cause range op to start looking for the next START token.

The performance is unlikely to become significantly faster because the "expensive" part is the I/O. Perl regex is very fast. Anyway instead of thinking "break", think about what ending regex would be more appropriate.

Update: It could be that a more traditional parsing would work better instead of the regex range operation for this application.

while (<$fh>) { process_block() if /^START/; } sub process_block { while (<$fh>) { return() if /^END/; return() if "data isn't cool anymore"; #pseudo code ..process cool data.. #pseudo code } }

In reply to Re: Breaking out of a matching block by Marshall
in thread Breaking out of a matching block by yoda54

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.