I assume that you are referring to Metatag processing (overlapping regions)?

Now first of all I would take what was the general first recommendation quite seriously - solve this in multiple passes. I would also simplify your logic - do you really need the nested logic?

But if you want to proceed with the second, I would avoid ever using $` etc. If you look closely I did that with Why I like functional programming which I pointed you at before. Using those special variables slows down all REs, and you are going to use a lot of them. Instead I would arrange (as I did) to pass through the string caching everything just once.

Even so a single pass with s///; is going to be much faster than a single pass with this more sophisticated algorithm for a whole ton of reasons. For instance it is looping in C, you are in Perl, so there is a factor of 10 difference right there. (Which is one of the reasons that so many suggested that you go with KISS until you don't have a choice.) But when the logic goes beyond what multiple passes can readily handle, or if you are making enough passes that don't do much, then the performance difference will reverse. This is often true. Do something sophisticated and you take an immediate performance hit - but then scale to more complex logic better.


In reply to Re (tilly) 1: Why is while(m//g){} so much slower than s///eg and what can I do about it? by tilly
in thread Why is while(m//g){} so much slower than s///eg and what can I do about it? by kaatunut

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.