Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: updating a variable call in a hash table

by gnosti (Friar)
on Feb 09, 2009 at 03:57 UTC ( #742344=note: print w/ replies, xml ) Need Help??


in reply to Re^2: updating a variable call in a hash table
in thread updating a variable call in a hash table

Is there no simple way to do this w/o invoking a module?

Sure there is!

$sentence = q("The next color is $color."); $color = q(blue); print eval $sentence;
You can learn how to be lazy later :-)

Note: There can be security implications if $color is supplied by user input.


Comment on Re^3: updating a variable call in a hash table
Download Code
Replies are listed 'Best First'.
Re^4: updating a variable call in a hash table
by AnomalousMonk (Abbot) on Feb 09, 2009 at 06:18 UTC
    Note: There can be security implications if $color is supplied by user input.
    Famous last words!
Re^4: updating a variable call in a hash table
by shmem (Canon) on Feb 09, 2009 at 13:32 UTC

    No need for eval.

    $sentence = sub { "The next color is ". shift }; $color = q(blue); print $sentence->($color);
Re^4: updating a variable call in a hash table
by coopermc (Initiate) on Feb 09, 2009 at 04:48 UTC
    Aha, that is what I was after. Thank you.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-28 06:25 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 (252 votes), past polls