| Next | Tricks of the Wizards | 66 |
Magic hash is not limited to evaluation:
package Format_Money;
sub FETCH {
my ($dummy, $amount) = @_;
my ($dollars, $cents) = split /\./, sprintf("%.2f", $amount);
1 while $dollars =~ s/^([-+]?\d+)(\d{3})/$1,$2/; # FAQ
"\$$dollars.$cents";
}
Now:
use Format_Money;
$salary = 43_000;
print "After your raise, you will make $Money{$salary*1.06}.\n";
After your raise, you will make $45,580.00
Also use for automatic URL character escaping (for example)
Also see Interpolation module
| Next | ![]() |
Copyright © 2003 M. J. Dominus |