in reply to Dreaming of Post Interpolation

Here's my stab at it. By storing the original text in a function instead of a scalar I can delay interpolation of the $vars until call time. See this example:
$text = sub { <<EOT; Dear $person, I know that this text is $adjective. But I wish it could be... EOT }; local $person = 'Mom'; local $adjective = 'not interpolated'; print &$text;
I don't think this is quite what you were looking for, but I think it is along the right path. I have a feeling that something with eval might do the trick too, but I can't figure out how to get that to work right now.

Replies are listed 'Best First'.
RE: Re: Dreaming of Post Interpolation
by BBQ (Curate) on May 30, 2000 at 06:35 UTC
    Hey! That's very close to the general idea! But it doesn't deal with my previous post with numbers... The delaying part is attractive, but unfortunately you only get to do one assignment. I would like to have several variables (and variables composed from those) affected by change of one.

    The best reference that pops into mind (and the simplest one) is Excel. Kinda like having an entire column defined from a cell, then cascading down the line when you change the value of that cell.

    But, delaying works admirably when you're dealing with a single variable. It would just be a pain in the behind to have to do that for each (no pun intended) one of them all.
      Unless I misunderstand what you're asking for; you can do the assignment multiple times with different values:
      $text = sub { <<EOT; Dear $person, I know that this text is $adjective. But I wish it could be... EOT }; my @subs=('Mom:not interpolates', 'Dad:maybe interpolated', 'Sis:who knows'); foreach (@subs){ local ($person,$adjevtive)=split ':',$_; print &$text; }
      My technique will also work for your number example (with everything stored as a function). However it look slightly ugly:
      $n = sub {1}; $m = sub {&$n*2}; $o = sub {&$m*2}; $s = sub {&$n." ".&$m." ".&$o."\n"}; print &$s; $n = sub {2}; print &$s;