Next | The Identity Function | 12 |
use Eval; print "Next year, I will make $Eval{$SALARY*1.06} dollars\n";
%Eval is a tied hash, so the FETCH method is called:
sub FETCH { $_[1] } # Identity function
It is called with the argument "47700"
It then returns "47700" as the value 'stored' in the hash
Result:
Next year, I will make 47700 dollars
Or if you prefer:
print "The square root of 2 is $Eval{sprintf("%.4f", sqrt(2))}\n";
print "The employee's name is $Eval{$employee->name}\n";
Andrew Pimlott invented this trick
Next | Copyright © 2001 M. J. Dominus |