<?xml version="1.0" encoding="windows-1252"?>
<node id="964264" title="Re: Common Perl Pitfalls" created="2012-04-10 02:49:28" updated="2012-04-10 02:49:28">
<type id="11">
note</type>
<author id="699288">
JavaFan</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;em&gt;Of course if you had meant the string $to_replace is an actual regex to match against, you're better off using the qr operator:&lt;/em&gt;&lt;/blockquote&gt;
I don't get this point. You started off that section with:
&lt;code&gt;
$to_replace='some_string';
$my_string=~ s/$to_replace/$better_data/;
&lt;/code&gt;
and doomed this &lt;em&gt;catastrophically unsafe&lt;/em&gt;, because &lt;tt&gt;$to_replace&lt;/tt&gt; may actually contain characters that have a special meaning.
&lt;p&gt;
But if &lt;tt&gt;$to_replace&lt;/tt&gt; is actually a regexp, the premises is gone -- any special characters are intentional. In fact, it's quite fine in that case to use the above.</field>
<field name="root_node">
964216</field>
<field name="parent_node">
964216</field>
</data>
</node>
