traveler has asked for the wisdom of the Perl Monks concerning the following question:
Of course, $str is "foo has the value $foo". I'd like to do "variable interpolation" on $str. I thought eval might do that, but is unhappy trying to do just that. I believe that there is a simple answer, but it is one of those days when the mind gets totally fogged...sub fun{ return sub {return 'foo has value $foo'); } ... $coderef = fun; $foo = 7; $str = &$coderef;
When I tried double quotes around the string, it tried to evaluate $foo (which was undefined) and created a closure with the string having an undefined value.
As always, any help is appreciated,
--traveler
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delaying interpolation
by meonkeys (Chaplain) on Aug 07, 2001 at 04:22 UTC | |
|
Re: Delaying interpolation
by abstracts (Hermit) on Aug 07, 2001 at 04:26 UTC | |
|
Re: Delaying interpolation
by chipmunk (Parson) on Aug 07, 2001 at 06:39 UTC | |
|
Re: Delaying interpolation
by traveler (Parson) on Aug 07, 2001 at 05:01 UTC |