I'm still attempting to narrow down the cause of this problem.

I have some code which constructs a large HTML table where I need to color adjacent cells if their content meets a certain criteria. Thankfully, the entire table is constructed before being sent to STDOUT, so I can easily construct a regular expression which would search for the errant combination and color it appropriately before displaying. The substitution is similar to the following:

$table =~ s!<td>(bad condition text 1 \[<a href=".+?">toggle</a>\])</t +d><td>(bad condition text 2 \[<a href=".+?">toggle</a>\])</td>!<td st +yle="background-color:orange">$1</td><td style="back\ ground-color:orange">$2</td>!gs;
This code lives in a CGI file. The first time it executes, it colors the adjacent bad combinations correctly, but if the user clicks on specific links which causes the table to be redisplayed, instead of only coloring bad combinations, it appears that disjoint combinations (not adjacent) table elements are colored instead.

My guess (which may be completely wrong) is that some state variables used by the regular expression engine are not being reinitialized upon subsequent displays of the table -- hence, why disjoint elements may be colored.

I may be completely wrong in this hypothesis, but I can't come up with an alternative explanation to explain the behavior seen.

Any insight you may have which explains this odd behavior would certainly be appreciated.


In reply to initializing internal regex variables? 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.