<p>Yea, that&#39;s what I get for trying to be creative when I try to simplify an example down for an email, currently using &quot;..&quot;, not &quot;\d\d&quot;</p>
<p>I&#39;ve run across qr// before, not quite sure exactly what use I might have for it, but I&#39;ll take a look...</p>
<p>@Matt, c modifyer looks like what I need.... I&#39;m already using arrays and a loop, will check it out..</p>
<p>In other news, for a completely different problem in the script, I recently came across File::Slurp... I could probably make more use of it in this case.  (It let me reduce some other code from 21 lines to 5, and I assume the overhead isn&#39;t bad, as I&#39;ve read it&#39;s being included natively with Perl 6...) *shrug*</p>

<p>-John</p>
<div class="gmail_quote">On Feb 23, 2011 12:49 AM, &quot;Mike South&quot; &lt;<a href="mailto:msouth@gmail.com">msouth@gmail.com</a>&gt; wrote:<br type="attribution">&gt; Also those \d&#39;s aren&#39;t going to match A-F are they?<br>
&gt; <br>&gt; Are you familiar with qr// to let you store a regex bit in a variable?  That<br>&gt; might make some of this more readable.<br>&gt; <br>&gt; mike<br>&gt; <br>&gt; On Tue, Feb 22, 2011 at 10:58 PM, Matt Nash &lt;<a href="mailto:mattnashbrowns@gmail.com">mattnashbrowns@gmail.com</a>&gt;wrote:<br>
&gt; <br>&gt;&gt; Of course, you want actual spaces (not &#39;\s&#39;) in the replace string, but you<br>&gt;&gt; knew that.<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; On Tue, Feb 22, 2011 at 9:56 PM, Matt Nash &lt;<a href="mailto:mattnashbrowns@gmail.com">mattnashbrowns@gmail.com</a>&gt;wrote:<br>
&gt;&gt;<br>&gt;&gt;&gt; Hi John,<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; You are reading the entire file into an array of lines, then processing<br>&gt;&gt;&gt; that array using a C-style for loop and interpolating the index var into the<br>
&gt;&gt;&gt; search string... and that is the LEAST crazy thing. :)  It works, of course,<br>&gt;&gt;&gt; because it turns out that there are infinitely many ways to do it.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; For your immediate problem of the search-and-replace, I recommend reading<br>
&gt;&gt;&gt; the  whole file into a single string, newlines and all, then using the /gc<br>&gt;&gt;&gt; modifiers in the regex.  Maybe put your colorChange stuff into an array that<br>&gt;&gt;&gt; you loop through, checking the regex for the nth match:<br>
&gt;&gt;&gt;<br>&gt;&gt;&gt; @changes = ($change1, $change2, $change3);<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; foreach $change (@changes) {<br>&gt;&gt;&gt;     $wholefile =~<br>&gt;&gt;&gt; s|08\s00\s00\s1C\s\d\d\s\d\d\s\d\d\s\d\d|08\s00\s00\s1C\s$change|gc;<br>
&gt;&gt;&gt; }<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; see <a href="http://perldoc.perl.org/perlre.html">http://perldoc.perl.org/perlre.html</a> and<br>&gt;&gt;&gt; <a href="http://perldoc.perl.org/perlretut.htm">http://perldoc.perl.org/perlretut.htm</a>&lt;<a href="http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl">http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl</a>&gt; for<br>
&gt;&gt;&gt; lots of details, but the upshot of the modifiers is: g makes it keep looking<br>&gt;&gt;&gt; for matches; c tells it to remember where it last matched, and start from<br>&gt;&gt;&gt; there on the next match.  You don&#39;t have to care what n is, because you are<br>
&gt;&gt;&gt; matching your search string exactly as many times as you have changes to<br>&gt;&gt;&gt; make.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; ...but this project sounds ripe for refactoring, if I may be so bold.<br>&gt;&gt;&gt;  Could it be that what you really need is a templating system?<br>
&gt;&gt;&gt;<br>&gt;&gt;&gt; Thanks for bringing some much-needed questions to this list!<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; Matt<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On Tue, Feb 22, 2011 at 8:31 PM, John Ricker &lt;<a href="mailto:sephtin%2Bpm-talk@gmail.com">sephtin+pm-talk@gmail.com</a>&gt;wrote:<br>
&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Received so much help with the last question (which seems to be<br>&gt;&gt;&gt;&gt; functioning great, btw.. thanks all)... thought I&#39;d try again.  ;)<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Have a script that was recently migrated to Perl from shell/bash, and am<br>
&gt;&gt;&gt;&gt; wondering if there&#39;s an easy way in Perl to do the following-<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; File(s) being modified are hex, and look something like:<br>&gt;&gt;&gt;&gt; ---x---<br>&gt;&gt;&gt;&gt; ...<br>
&gt;&gt;&gt;&gt; 08 00 00 00 FF FF FF FF FF FF FF FF 1B 00 00 00 02 01 10 00 28 01 00 00<br>&gt;&gt;&gt;&gt; 09 00 00 00 FF FF FF FF FF FF FF FF 1C 00 00 00 14 00 14 00 0D 00 00 00 00<br>&gt;&gt;&gt;&gt; 00 0D 00 18 00 00 00 11 00 00 00 FF FF FF FF 08 00 00 05 02 0E 00 00 18 00<br>
&gt;&gt;&gt;&gt; 00 00 0E 00 00 00 FF FF FF FF 08 00 00 1C 00 00 00 FF 18 00 00 00 09 00 00<br>&gt;&gt;&gt;&gt; 00 FF FF FF FF 08 00 00 11 10 00 00 00 18 00 00 00 0F 00 00 00 FF FF FF FF<br>&gt;&gt;&gt;&gt; 08 00 00 01 11 02 02 01 18 00 00 00 03 00 00 00 FF FF FF FF 08 00 00 01 05<br>
&gt;&gt;&gt;&gt; 00 08 01 18 00 00 00 10 00 00 00 FF FF FF FF 08 00 00 05 01 0F 00 00 18 00<br>&gt;&gt;&gt;&gt; 00 00 05 00 00 00 FF FF FF FF 08 00 00 05 01 0F 00 00 18 00 00<br>&gt;&gt;&gt;&gt; ...<br>&gt;&gt;&gt;&gt; ---x---<br>
&gt;&gt;&gt;&gt; File(s) contain several occurrences of &quot;08 00 00 1c ## ## ## ##&quot; or more<br>&gt;&gt;&gt;&gt; appropriately for this list: &quot;08\s00\s00\s1C\s\d\d\s\d\d\s\d\d\s\d\d&quot;<br>&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;  Now on to the good stuff...  I would like to replace the ## ## ## ##<br>&gt;&gt;&gt;&gt; with my chosen colors, that are being provided by vars... Example:<br>&gt;&gt;&gt;&gt; colorChange1=&quot;FF 00 00 FF&quot;<br>
&gt;&gt;&gt;&gt; colorChange2=&quot;FF FF 00 FF&quot;<br>&gt;&gt;&gt;&gt; colorChange3=&quot;FF 00 FF FF&quot;<br>&gt;&gt;&gt;&gt; ...<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; I&#39;m wondering how it might be possible, to replace the FIRST occurrence<br>
&gt;&gt;&gt;&gt; (in the file, NOT in a line) of &quot;08 00 00 1C ## ## ## ##&quot; with &quot;08 00 00 1C<br>&gt;&gt;&gt;&gt; $colorChange1&quot;, the second with &quot;08 00 00 1C $colorChange2&quot;, etc.<br>&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; More info:<br>&gt;&gt;&gt;&gt; --Script modifies files to theme them, in this case, I&#39;m taking a BINARY<br>&gt;&gt;&gt;&gt; (compiled XML) file, converting it to HEX via xxd, and then changing the<br>
&gt;&gt;&gt;&gt; text color for a theme via substitution.<br>&gt;&gt;&gt;&gt; --I originally thought it could be done similar to what sed does... with<br>&gt;&gt;&gt;&gt; s|(08\s00\s00\s1C)\s\d\d\s\d\d\s\d\d\s\d\d|$1$colorChange1|1  (note last<br>
&gt;&gt;&gt;&gt; digit...), but testing has shown that this doesn&#39;t work as expected.<br>&gt;&gt;&gt;&gt; --Not really related, but in the binary, the colors are actually<br>&gt;&gt;&gt;&gt; backwards, so color - FF AB CD EF becomes binary - EF CD AB FF, but that&#39;s<br>
&gt;&gt;&gt;&gt; an easy change.<br>&gt;&gt;&gt;&gt; --CURRENTLY in my script, I&#39;m doing this via a sub, passing an array of<br>&gt;&gt;&gt;&gt; the colors, the file, and the file location (directory), and pulling the<br>
&gt;&gt;&gt;&gt; file, making the changes, and saving it back out via loop... BUT, because I<br>&gt;&gt;&gt;&gt; couldn&#39;t figure out how to just do the multiple replaces... I cheated and<br>&gt;&gt;&gt;&gt; made template files that contain &quot;08 00 00 1C 11 11 11 11&quot; and &quot;08 00 00 1C<br>
&gt;&gt;&gt;&gt; 22 22 22 22&quot;, so when I iterate through the loop, I just change like so:<br>&gt;&gt;&gt;&gt; for ( $i = 1 ; $i &lt;= $COUNT ; $i++ ) {<br>&gt;&gt;&gt;&gt; ...<br>&gt;&gt;&gt;&gt;     $line =~ s|08\s00\s00\s1c\s$i$i\s$i$i\s$i$i\s$i$i\s|08 00 00 1c<br>
&gt;&gt;&gt;&gt; $array_ref[$i]|;<br>&gt;&gt;&gt;&gt; ...<br>&gt;&gt;&gt;&gt; }<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Code works, but I&#39;d much rather be able to pull native files straight out<br>&gt;&gt;&gt;&gt; of the .zip, and change them that way... :P<br>
&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Anyway, again, if there are specifics I missed, happy to provide them.<br>&gt;&gt;&gt;&gt; I keep thinking there should be an easy way to do this... but my<br>&gt;&gt;&gt;&gt; google-fu is failing me..<br>
&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Thanks again for the help with the previous problem, and in advance for<br>&gt;&gt;&gt;&gt; any assistance on this one.  :)<br>&gt;&gt;&gt;&gt; At the very least, I guess I can provide some chatter to the group.<br>
&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; -John (sephtin @gmail)<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; _______________________________________________<br>&gt;&gt;&gt;&gt; Raleigh-talk mailing list<br>&gt;&gt;&gt;&gt; <a href="mailto:Raleigh-talk@pm.org">Raleigh-talk@pm.org</a><br>
&gt;&gt;&gt;&gt; <a href="http://mail.pm.org/mailman/listinfo/raleigh-talk">http://mail.pm.org/mailman/listinfo/raleigh-talk</a><br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>
&gt;&gt; Raleigh-talk mailing list<br>&gt;&gt; <a href="mailto:Raleigh-talk@pm.org">Raleigh-talk@pm.org</a><br>&gt;&gt; <a href="http://mail.pm.org/mailman/listinfo/raleigh-talk">http://mail.pm.org/mailman/listinfo/raleigh-talk</a><br>
&gt;&gt;<br>&gt;&gt;<br></div>