Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by jeffa (Chancellor)
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)


Comment on (jeffa) 3Re: A better mod (%) operator?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://180380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-09-02 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (32 votes), past polls