Next | The Perl Hardware Store | DC.pm Version | 60 |
Here the hash key is evaluated (by Perl) and returned unchanged (by us):
sub FETCH { $_[1]; }
We can profit by changing it.
For example:
sub FETCH { my $key = sprintf("%.2f", abs($_[1])); my $positive = $_[1] > 0; 1 while $key =~ s/^([-+]?\d+)(\d{3})/$1,$2/; # FAQ $positive ? " \$$key " : "(\$$key)"; }
Now:
use Eval '$'; $EARNINGS = 47387.12; $EXPENSES = 55337.48; print "This year we earned $${$EARNINGS} and expended $${EXPENSES}.\n" print "Net profits were $${$EARNINGS-$EXPENSES}.\n";
prints
This year we earned $47,387.12 and expended $55,337.48. Net profits were ($7,950.36).
Next | Copyright © 2003 M. J. Dominus |