in reply to Re: How Does Interpolation Work?
in thread How Does Interpolation Work?
Oh, you asked for it!
Mark-Jason Dominus presented this at the Perl Conference. It's a generic way to evaluate a Perl expression inside a double-quoted string:
package Eval; sub import { my ($package, $name) = @_; $name = 'Eval' unless defined $name; my %magical_hash; tie %magical_hash =>Eval; my $caller = caller; *{caller . '::' . $name} = \%magical_hash; } sub TIEHASH { my $self = \'fake'; bless $self => Eval; } sub FETCH { my ($self, $value) = @_; $value; }
Looks pretty freaky, eh? Okay, now try this:
use Eval => ':'; $salary = 43_000; print "After your raise, you will make $:{$salary*1.06}.\n";
Yeek. Have fun!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Re: How Does Interpolation Work? (CMonster: method call eval)
by jeorgen (Pilgrim) on Jul 22, 2000 at 14:45 UTC | |
by chromatic (Archbishop) on Jul 23, 2000 at 08:02 UTC |