#!/usr/bin/env perl -w use Math::Complex; $z = Math::Complex->make(5, 6); print "z first equals: $z\n"; #Two different ways of calling instance methods: $real = $z->Re(); $img = Math::Complex::Im($z); print "The real part of $z is $real, and the imaginary part is $img\n"; #Using overloaded = and +, and constant i $y = 4 + 3*i; print "y = $y\n"; $ry = $y->Re(); $iy = $y->Im(); print "Real y = $ry\tImg y = $iy\n"; #More overloading $x = 10 + 5*i + $z; print "x = $x\n"; $rx = $x->Re(); $ix = $x->Im(); print "Real x = $rx\tImg x = $ix\n"; #Setting pieces of complex numbers, the way the writer intended $x->Re(20); $x->Im(40); print "x is now = $x\n"; #Demonstrating that class variables are not private ${$z->cartesian}[0] = 40; #Don't do this!!! $real = $z->Re(); $img = Math::Complex::Im($z); print "The real part of $z is $real, and the imaginary part is $img\n";