http://www.perlmonks.org?node_id=153102


in reply to Variable Interpolation Interpolation

You can just eval the bit where you want to get the variable's value:

foreach my $f (@fields) { my $val = eval qq{ \$fromQuery::$f }; next unless $val; push(\@where, $val); push(\@searchString, $val); }

But I am sure that dragonchild's solution is faster. The only gotcha is that it won't run under strict but no strict 'refs'; in the correct scope will turn off that check:

foreach my $f (@fields) { no strict 'refs'; # This will only last in this scope my $val = ${ "fromQuery::$f" }; next unless $val; push(\@where, $val); push(\@searchString, $val); }

-ben