vim Centsible.pm
package Centsible;
sub TIESCALAR {bless \my $self,shift}
sub STORE { ${ $_[0] } = $_[1]}
sub FETCH {sprintf "%0.2f",${my $self = shift}}
1;
vim main.pl
use Centsible;
package main;
use Centsible;
tie $bucks,"Centsible";
$bucks = 45.00;
$bucks *= 1.0715;
$bucks *= 1.0715;
print "That will be $bucks,please.\n";
注意的捆绑过程!
阅读(1483) | 评论(0) | 转发(0) |