<?xml version="1.0" encoding="windows-1252"?>
<node id="735481" title="Re: Bug in substitution operator?" created="2009-01-11 03:22:09" updated="2009-01-11 03:22:09">
<type id="11">
note</type>
<author id="704949">
fullermd</author>
<data>
<field name="doctext">
&lt;p&gt;
Interesting.  It does sound buggy.
&lt;/p&gt;

&lt;p&gt;
And it does the same thing with brackets too, notice.  Simpler example:
&lt;/p&gt;

&lt;code&gt;
@s = ("foo bar baz") x 4;
$bar = "rab";
%bar = (1 =&gt; "eek");
@bar = (undef, 'oof');

$s[0] =~ s{(bar)} {$bar\{1\}};
$s[1] =~ s{(bar)} [$bar\{1\}];

$s[2] =~ s{(bar)} {$bar\[1\]};
$s[3] =~ s{(bar)} [$bar\[1\]];

for $i (0..3)
{ print "$i -&gt; '$s[$i]'\n"; }
&lt;/code&gt;

&lt;p&gt;Yields&lt;/h2&gt;

&lt;code&gt;
0 -&gt; 'foo eek baz'
1 -&gt; 'foo rab{1} baz'
2 -&gt; 'foo rab[1] baz'
3 -&gt; 'foo oof baz'
&lt;/code&gt;

&lt;p&gt;(5.8 here)&lt;/p&gt;

&lt;p&gt;
So something about having the delimiter be the same as your subscripting character makes it real hard to escape.
&lt;/p&gt;

&lt;p&gt;
For extra fun, notice that using two \'s in the sub fails as "replacement not terminated", and using 3 leaves one sitting in your string:
&lt;/p&gt;

&lt;code&gt;
4 -&gt; 'foo rab\[1] baz'
&lt;/code&gt;

&lt;p&gt;
So it doesn't seem like you can all that easily work around it except by changing the delimiters.  Maybe playing with escaping...  yes, that seems to work:
&lt;/p&gt;

&lt;code&gt;
$s[4] =~ s{(bar)} [$bar\E\[1\]];

4 -&gt; 'foo rab[1] baz'
&lt;/code&gt;

&lt;p&gt;
Wackiness.
&lt;/p&gt;</field>
<field name="root_node">
735426</field>
<field name="parent_node">
735426</field>
</data>
</node>
