Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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
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.
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);

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 imbibing at the Monastery: (22)
As of 2014-10-20 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (77 votes), past polls