<?xml version="1.0" encoding="windows-1252"?>
<node id="1003476" title="Re: Evaling Strings in Subs for Hashref Variable Names to Values" created="2012-11-12 11:21:20" updated="2012-11-12 11:21:20">
<type id="11">
note</type>
<author id="832495">
choroba</author>
<data>
<field name="doctext">
If you use &lt;c&gt;next&lt;/c&gt;, there is no need to use &lt;c&gt;else&lt;/c&gt;: the code after &lt;c&gt;next&lt;/c&gt; can only be reached if the condition was not true.
&lt;p&gt;
You do not want to use &lt;c&gt;eval BLOCK&lt;/c&gt; to catch exceptions. You want to use &lt;c&gt;eval STRING&lt;/c&gt; to evaluate a constructed code. You should include the assignment in the code, though:
&lt;c&gt;
#!/usr/bin/perl
use warnings;
use strict;

my $sql_var_hr;
$sql_var_hr-&gt;{col_name} = 'column_name';
my $sql = get_sql($sql_var_hr);


sub get_sql {
	my ($vars) = @_;
	my $sql;

	while (my $iline = &lt;DATA&gt;) {
            next if $iline =~ /^#/;
            $sql .= $iline;
	}
	print "pre_eval: $sql\n";
	eval '$sql = "' . $sql . '"' or warn $@;
	print "post_eval: $sql\n";
	return $sql;
}

__DATA__
select $vars-&gt;{col_name} from schema.table
select $$vars{col_name} from schema.table
&lt;/c&gt;
Using "templates" might solve lots of problems this naïve approach might cause.
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-832495"&gt;

&amp;#1604;&amp;#1405;&amp;#4285;† &amp;#6514;&amp;#6482;&amp;#9898;&amp;#10186;&amp;#4281;&amp;#5651;&amp;#5511; &amp;#5045;&amp;#5651;&amp;#5511;&amp;#9137; &amp;#4281;&amp;#6514;&amp;#119243;&amp;#409;&amp;#5651;&amp;#5511;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1003474</field>
<field name="parent_node">
1003474</field>
</data>
</node>
