Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Looking for equivalent to LHS eval

by simonm (Vicar)
on Jul 17, 2003 at 15:45 UTC ( [id://275258]=note: print w/replies, xml ) Need Help??


in reply to Looking for equivalent to LHS eval

Yup, it's just a matter of figuring out what gets quoted; this should do it:
%hash = ( key1 => 'A', key2 => 'B', key3 => 'C' ); for my $key ( qw/key1 key2 key3/ ) { eval( '$' . "$key = \$hash{\$key}"; } print $key1 . $key2 . $key3;

Replies are listed 'Best First'.
•Re: Re: Looking for equivalent to LHS eval
by merlyn (Sage) on Jul 17, 2003 at 16:02 UTC
    Uh, no. You really really don't want to do this. This would be the greater of two evils, the lesser of which would be using symbolic references. And if that's discouraged, using eval to do the same thing is discouraged-squared. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-23 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found