Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Variable Interpolation Interpolation

by knobunc (Pilgrim)
on Mar 20, 2002 at 19:42 UTC ( #153102=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Variable Interpolation Interpolation
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://153102]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-02 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls