<html>
At 11:23 PM 12/20/03 -0800, Fred Morris wrote:<br>
<blockquote type=cite class=cite cite>Interestingly, my brain-dead
workaround seems to perform slightly better<br>
than eval for a smallish number of substitutions; it also doesn't
kick<br>
errors when a variable isn't defined (it just leaves it alone). (8
seconds<br>
versus 10 seconds)<br>
</blockquote><br>
[snip]<br>
<br>
<blockquote type=cite class=cite cite>&nbsp; for (my $i = 0; $i &lt;
20000; $i++) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $s = eval ' my $s = &quot;' . $source .
'&quot;;';<br>
&nbsp; }<br>
</blockquote><br>
You are doing &quot;my $s&quot; twice in the same lexical context.&nbsp;
Additionally, looking at 'perldoc -f eval' reveals <br>
<br>
&gt; In both forms, the value returned is the value of the last<br>
&gt; expression evaluated inside the mini-program;<br>
<br>
So you really only need <br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>my $s =
eval qq[&quot;$source&quot;];<br>
<br>
Further reading of the perldoc tells us that in this form, the EXPR is
parsed every time the statement executes.&nbsp; That is where you get the
slowdown.&nbsp; But that also is where you get the ability to expand
variables of which you don't know the names, as Brian has already pointed
out.&nbsp; I tried playing around with a regex kind of like
&quot;s/\$(\w+)/$$1/g&quot; (turning off strict) but it was not
interpolating correctly.&nbsp; The only way it will work is like 
so:<br>

<dl>
<dl>
<dd>#! /usr/bin/perl<br>
<br>

<dd>$foo_str = &quot;foo&quot;;
<dd>$bar_str = &quot;bar&quot;;<br>
<br>

<dd>my $foo = 'substitute $foo_str for $bar_str';<br>
<br>

<dd>my $s = &quot;&quot;;
<dd>print &quot;go?&gt;&quot;;
<dd>$line = &lt;&gt;;
<dd>for (my $i = 0; $i&lt;2000; $i++) {
<dd>&nbsp; $s = eval {
<dd>&nbsp;&nbsp;&nbsp; my $str = $foo;
<dd>&nbsp;&nbsp;&nbsp; $str =~ s/\$(\w+)/$$1/g;
<dd>&nbsp;&nbsp;&nbsp; return $str;
<dd>&nbsp; };
<dd>}
<dd>print &quot;\$s = $s;\n&quot;;<br>
<br>

</dl>
</dl>I don't know exactly why, but putting &quot;my&quot; on $foo_str and
$bar_str caused things to break.&nbsp; I know it has to do with scope
some-how, but I don't know the exact reason.&nbsp; So, if you want fast,
but completely non-strict, there's a solution for you.<br>
<br>
Ivan</html>