http://qs321.pair.com?node_id=1070185


in reply to A better mod (%) operator?

If you are happy to lose the original numerator, you could do it with side effects on the arguments. The original numerator would become the result of div and the function itself would return the remainder. (Just for the fun of it in autoboxing notation...)

use strict; use warnings; my $rdiv = sub { my $num = $_[0]; $_[0] = int( $_[0]/$_[1] ); $num - $ +_[0]*$_[1] }; my $x = 11; my $y = 4; my $r = $x->$rdiv( $y ); print "$x, $r\n";