- or download this
package Complex;
use Carp;
...
return $self->[$position] = $value;
}
}
- or download this
use Complex;
#create a new object
my $x = new Complex;
...
$x->Imag(-5); #set $x's imaginary part to '-5'
print $x->Real." ".$y->Imag; #prints '3 -3'
- or download this
use overload
"\"\"" => \&Cmp_string,
"+" => \&Cmp_add,
"*" => \&Cmp_multiply;
- or download this
print $x; #prints '3 - 5I'
my $str = "$x"; #$str = '3 - 5I'
- or download this
$x = $x + $y;
$y = $x + 2;
$y = 2 + $x;
- or download this
$y = $x * $x;
$y = $x * 2;
$y = 2 * $x;
- or download this
sub Cmp_string
{
#get the object
...
# arithmetic
return new Complex($real, $imag);
}
- or download this
package Complex;
use Carp;
use strict;
...
#module exit status
1;