Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: updating a variable call in a hash table

by shmem (Chancellor)
on Feb 09, 2009 at 13:25 UTC ( [id://742417]=note: print w/replies, xml ) Need Help??


in reply to updating a variable call in a hash table

You could use an anonymous subroutine as the hash value for 'text':

%hash = ( "text" => sub { my $color_opt = shift; return <<"TEXTEND", We play the same game again, but with a different proportion of colore +d balls in + Box K (see below). Everything else is the same. <p> You can choose between box U or box K, both containing 100 balls of five different colors. One ball will be drawn from the box you have + chosen. You win &#36;1,000 if a $color_opt ball is drawn. <p> Please select the box of your choice: U or K. If you think both boxes are equally attractive, you can select Indiffe +rent. TEXTEND }, ); print $hash{text}->("blue"); print $hash{text}->("chartreuse");

That way the interpolation is done when you evaluate the hash value (i.e. call the subroutine).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found