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


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.

Replies are listed 'Best First'.
Re^4: updating a variable call in a hash table
by AnomalousMonk (Archbishop) 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 (Chancellor) 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.