I have a program that does the following. It goes out and gets a series of web pages. The web pages have the same format. On each page I match a regular expression as many times as it occurs. The basic form is  while ($content =~ m%pattern%gs) { Do something }. Here's my problem.

The match works fine on some web pages -- putting out any and all matches. On some web pages, however, it puts out all of the matches and then "hangs". It just keeps running and running and running and never moves on to the next web page.

So, my questions are, what do you think is going on here? Is it some sort of infinite loop? Also, what can I do to debug the code?

The confusing thing for me is that it works fine on some pages and then hangs on others. Also, to my naked eye, the pages that it hangs on don't seem (overtly) any different from the ones that it doesn't hang on.

Thanks in advance for your help!


In reply to Regex infinite loop? by Ninth Prince

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.