Next | Tricks of the Wizards | 152 |
Program now croaks on $year % 100, $year + 1900, etc.
One solution: Just add modulus, addition, etc. methods.
Another solution:
package y2k; ... use overload 'nomethod' => \&default; ... sub default { my ($y2k, $arg, $rev, $op) = @_; my $y = $y2k->{YEAR}; my $expr = $rev ? "$arg $op $y" : "$y $op $arg"; eval $expr; }
Next | Copyright © 2003 M. J. Dominus |