Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Dreaming of Post Interpolation

by Anonymous Monk
on May 30, 2000 at 20:49 UTC ( #15437=note: print w/ replies, xml ) Need Help??


in reply to Dreaming of Post Interpolation

my $text = q{
  Dear $person,
  I know that this text is $adjective.
  But I wish it could be...

};

my $person    = 'Mom';
my $adjective = 'not interpolated';

print eval "qq{$text}";


Comment on Re: Dreaming of Post Interpolation
RE: Re: Dreaming of Post Interpolation
by mdillon (Priest) on May 30, 2000 at 20:52 UTC
    YES!

    this is the cleanest i've seen yet. the only thing that breaks this is unbalanced brackets, but in a 'sub interpolate', it's easy enough to get around such restrictions.

    on a side note, the Interpolate module doesn't really help much for BBQ's problem. this solution, however, gets perl to do real double-quotish interpolation on an arbitrary scalar value.

      Yeah, the Interpolat module wasn't as good as what it looked like from the examples. It just does a few tricks with hashes, and seems to be directed towards maintainin string formats more than actually doing heavy linkage.

      I think that what I was looking for is a new data state. Something that would cascade through whatever assignments had been done before. My numeric example was probably the best way to demonstrate. Come to think of it, cascade sounds like a cool name. Imagine it:
      cascade $n = 1; my $m = $n*2; my $o = $m*2; my $s = "$n $m $o\n"; print $s; $n = 2; print $s; ^d 1 2 4 2 4 8
      now would THAT be cool? Does anyone know if there a perl ideas/wishlist somewhere?

      #!/home/bbq/bin/perl
      # Trust no1!
        this is already possible with tie, although not quite so transparently. however, i'm sure that creative use of 'use overload' could be used to achieve the desired effect.
        Hmm. Seems to me that this could be done with a fancy Tie somehow. Not quite as you have posted it though....Perhaps if $m, $o, and $s were also cascaded...
        How far would you want this to go? While the above example could be done, I can see it getting messy with subroutine calls. For example:
        $n=1; #we have no idea which variables should be cascaded. $subref=sub { return $n *3 }; print &$subref, "\n"; $n=2; print &$subref, "\n";
        Will that output
        3
        6
        ?.
        Stream of conciousness: the Monitor package uses a tie on a variable to track when a variable is changed...can we track when it is accessed, and turn on cascading for any lvalue, etc? (I see dire consequences on the stack/heap, but...) Then when any such value is modified, you could go through the cascade stack and reset every value. It would go nuts on code like:
        use Cascade; cascade $n; cascade $m; $n=1; $m=$n; $n=$m+1;
        Because $m is altered by $n, and thus when we change $n, we recalc $m, which is in turn set by $n, so we recalc....

        But I guess this isn't much different from screwing your reference count by doing a $a=\$a (except of course that that doesn't hang).

        All speculation anyway, since I don't believe that there is any way to find what lvalue is affected by a variable reference.

        The trouble is, you'd have to completely scrap the way Perl handles assignments.

        For $foo = $bar + 1, the rhs is evaluated first and the result is stored in $foo. What you want is to store the rhs expression in $foo (ie, more or less a sub ref).

        And, as swiftone says, every variable that has a cascaded variable on the rhs of its assignment is forced to become a cascade variable itself, with potentially dire results. Perhaps meltdown would be a better name :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-11-27 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (177 votes), past polls