http://www.perlmonks.org?node_id=1007842


in reply to Overloaded operators calling similar functions...

This is a nicely-written program, well done! If the C++ version is up to this standard, you should get high marks on the assignment.

I did notice one logical error:

print "Division by zero not allowed, starting over..." and redo if ( $frac01 =~ /^[\s\S]?\/?0$/ );

If the user enters 1/0, this correctly flags division by zero. But,

How to fix this? One way would be to extract the denominator (if any) and test whether that is zero. But this is Perl, so TMTOWTDI.

Now to style: In Perl, it’s better to declare a variable as late as possible in the code. So, looking at this line:

my ( $f1, $f2, $frac01, $frac02, $command, $total ) = (0) x 6;

actually only $command needs to be declared before the outer while loop. The rest can safely be declared at the point of first use. (And yes, I would declare $total separately within each of the if / elsif blocks.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,