On Thu, 14 Sep 2000 18:37:22 -0500, David L. Nicol wrote:

>       print "Today's weather will be ${weather->temp} degrees and sunny.";
>
>which would follow the "You want something funny in your interpolated
>scalar's name or reference, you put it in curlies" rule.

I too feel that an approach like this would be far more generically
useful than this "$weather->temp" special case. I have said it before, I
know, but calling a generic function, not a method call, happens more to
me than this object access.

        print "You have to pay " . money($amount) ." dollars.";

But sacrificing the ${...} syntax doesn't feel right. Indeed, it *does*
execute the code in curlies, but it expects a scalar reference.

MJD has a "silly module" which can tie a hash to a function:
Interpolation.pm. I think I would like a special case, a specific hash
that is *always* tied to a function that returns the arguments. Make it,
for example, %$, %@ or %?. These are not in use now, are they?

        print "You have to pay $?{money($amount)} dollars.";


Implementation in Perl 5:

        tie %?, Hash::Eval;
        sub money {
            return sprintf '%4.2f', shift;
        }
        print "You owe me $?{money(12)} dollars.\n";

        package Hash::Eval;
        sub TIEHASH {
            my $self = shift;
            return bless {}, ref $self || $self;
        }
        sub FETCH {
            my $self = shift;
            return "@_";
        }

-- 
        Bart.

Reply via email to