Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

(jeffa) 3Re: A better mod (%) operator?

by jeffa (Bishop)
on Jul 09, 2002 at 02:18 UTC ( #180380=note: print w/replies, xml ) Need Help??


in reply to Re: (jeffa) Re: A better mod (%) operator?
in thread A better mod (%) operator?

Yep, you have to have a blessed package (an object) in order for overload to work - but who says you can't bless main? ;)
use strict; use overload '+' => sub { ${$_[0]} - ${$_[1]} }; use overload '-' => sub { ${$_[0]} + ${$_[1]} }; my ($x,$y) = (90,60); my $i = bless \$x, 'main'; my $j = bless \$y, 'main'; # objects use overloaded operators print $i + $j, $/; # 30 print $i - $j, $/; # 150 # normal scalars use Perl operators print $x + $y, $/; # 150 print $x - $y, $/; # 30

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://180380]
help
Chatterbox?
[marto]: not so great OS :P
Eily never heard of the movie "LanX"
[Eily]: the LanX OS either now that I think of it :P
[hippo]: Congratulations, Discipulus!
[Discipulus]: Satura Lanx was a latin genre of show
[Discipulus]: coming from the meaning of 'mixed dish'
[Discipulus]: thanks hippo! the hat you passed me was brand new and clean, thanks
LanX OS builds on multitasking humor ...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-07-28 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (426 votes). Check out past polls.