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";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A better mod (%) operator?
by BrowserUk (Patriarch) on Jan 10, 2014 at 20:36 UTC |
In Section
Meditations