use overload '*' => sub { my $div = int(${$_[0]} / ${$_[1]}); my $mod = ${$_[0]} % ${$_[1]}; return ($div, $mod); };
This still generates "30" for 90/30, regardless of
context ... it's as if overloaded operators are allways
called in some sort of bizarro scalar context where lists
are evaluated as their last element instead of their length...
package mod; use strict; use overload '*' => sub { return ('yakko', 'wakko', 'dot'); }; sub new { my ($class,$val) = @_; return bless \$val, $class; } package main; use strict; my $i = mod->new(90); my $j = mod->new(60); my @x = $i * $j; my $x = $i * $j; print "@x\n"; print "$x\n"; __END__ dot dot
Update: My bad, I totally spaced out on the fact that lists in scalar context evaluate to the last element... i was thinking of it just like an array.
In reply to Re: Re: (jeffa) Re: A better mod (%) operator?
by hossman
in thread A better mod (%) operator?
by BrowserUk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |