Next | Tricks of the Wizards | 141 |
In overloading, you redefine the effect of the standard Perl operators like + and . to have a special meaning for objects in a certain class.
Operator applications are transformed into method calls.
Syntax:
package MyClass; use overload '+' => \&myadd, '-' => \&mysubtract, ... ;
Now $obj1 - $x turns into
$obj1->mysubtract($x);
Next | Copyright © 2003 M. J. Dominus |