in reply to Using overload. Any complete (simple) examples?

Any complete but simple examples? How about one that i threw together over at (jeffa) 6Re: Perl vs. Python: Looking at the Code where i overloaded the += operator to work on "arrays"? Or how about the one at (jeffa) Re: A better mod (%) operator? where we attempted to return both the result and remainder from division? Oh wait! That was YOU who asked the original question!

Oh well, hope these will help. :)

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 Re: Using overload. Any complete (simple) examples?

Replies are listed 'Best First'.
Re: Re: Using overload. Any complete (simple) examples?
by BrowserUk (Patriarch) on Oct 07, 2003 at 21:21 UTC

    Thanks Jeffa. Believe me, I haven't forgotten about (jeffa) Re: A better mod (%) operator? and my reply at Re: (jeffa) Re: A better mod (%) operator? still stands. I've frequently used overload for individual and groups of math and boolean operators, probably because you gave me 'boost up' back then.

    However, whenever I've tried to use it with the more esoteric operators, notably, '""' and '0+' (Thanks Zaxo) but also "{}", "[]", I've often found myself fighting the compiler to get the effects I want ... as opposed, perhaps, to the effects that overload is designed to give me.

    I've read the overload docs so many times I almost know them verbatim, but I still get caught out every time I try to use it....as at Temporarily disabling overloaded operations..

    Individually, I can make them work fine (mostly:), but when I try to use large scale overlaoding, especially in classes that are not simple classes, but (for example) use inheritance, or even tieing, things start going astray.

    So, having looked around at a few complex uses like the Math::Big* suite, but found it difficult to follow as the are inherently complex beasties without the overloading, they also aren't pure perl, which makes it more difficult to trace stuff through in the debugger, I thought I'd ask if anyone knew of a fairly simple, but (more) complete worked example.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail