<div class="gmail_quote"><div>Hi all,</div><div><br></div><div>I&#39;ve got a Perl problem that&#39;s got me stumped. Any help would be appreciated.</div><div><br></div><div>Consider the following small perl program, which exemplifies a problem I am having with a script generates HTML sw verification reports, and is supposed to colorize numbers according to how they verified against what the numbers are supposed to be. To make things simpler, <span style="font-family:Arial, Helvetica, Georgia, sans-serif;font-size:12px;color:rgb(51, 51, 51);line-height:18px">“<span style="font-family:Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace;line-height:18px;font-size:12px;white-space:pre">&lt;span color=”green”&gt;1&lt;span&gt;</span>” is abbreviated as â€œ<span style="font-family:Consolas, Monaco, &#39;Courier New&#39;, Courier, monospace;line-height:18px;font-size:12px;white-space:pre">sg1s</span>“:</span></div>


<div><span style="font-family:Arial, Helvetica, Georgia, sans-serif;font-size:12px;color:rgb(51, 51, 51);line-height:18px"><pre>#! /bin/perl
$s = &quot;1 2 3 1 2 3 1 2 3&quot;; Â  Â  Â  Â  Â # what I have
$t = &quot;sg1s 2 3 sr1s 2 3 1 sy2s 3&quot;; # what I want
@nums = qw(1 1 2);
@cols = qw(g r y);
$i=$j=0;
$s =~ s!($nums[$i++])!s$cols[$j++]$1s!g;
print &quot;Want: &#39;$t&#39;\n&quot;;
print &quot;Got: Â &#39;$s&#39;\n&quot;;
print &quot;i is now $i\n&quot;;
print &quot;j is now $j\n&quot;;</pre><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">The output of this program is unfortunately:</p>


<pre>Want: &#39;sg1s 2 3 sr1s 2 3 1 sy2s 3&#39;
Got: Â &#39;sg1s 2 3 sr1s 2 3 sy1s 2 3&#39;
i is now 1
j is now 3</pre><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">Perl ended up incorrectly coloring the third â€˜1′ yellow, instead of the third â€˜2′, because in the substitution regular expression, the left (matching) side was evaluated/compiled only once, while the right (replacement) side was evaluated/interpolated three times (as desired).</p>


<p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">I know that there are ways to force the left side of the RE to compile only once (/o modifier, qr// operator), and there are ways to force eval in the right side (/e and /ee modifiers â€” although in this case, standard interpolation was sufficient), but is there any way I can force the <em>left</em> side to compile <em>multiple</em> times? (Even within the same /g substitution?) I tried a few constructs using the \G (start matching from previous position) zero-width assertion, but only managed to get myself into infinite loops.</p>


<p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">I&#39;d appreciate any help anyone can offer -- including &quot;What an idiot, the RIGHT way to do that is completely different! (And here it is...)&quot;</p>


<p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">thx for thinking for me!</p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:10px;padding-right:0px;padding-bottom:0px;padding-left:0px">


r</p></span></div><font color="#888888"><div><br></div><div><br></div>
</font></div><br>