Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.$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;
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: initializing internal regex variables?
by moritz (Cardinal) on Nov 17, 2009 at 07:45 UTC | |
|
Re: initializing internal regex variables?
by JavaFan (Canon) on Nov 17, 2009 at 10:59 UTC | |
by Anonymous Monk on Nov 17, 2009 at 19:44 UTC | |
by ikegami (Patriarch) on Nov 17, 2009 at 20:22 UTC | |
by Anonymous Monk on Nov 17, 2009 at 19:09 UTC | |
by JavaFan (Canon) on Nov 17, 2009 at 21:06 UTC | |
|
Re: initializing internal regex variables?
by gmargo (Hermit) on Nov 17, 2009 at 13:49 UTC | |
by Anonymous Monk on Nov 17, 2009 at 19:11 UTC |