in reply to overloading core function and non-existing operator

I think you're misunderstanding the meaning of overloading, at least in Perl. Overloading does not mean (re)-defining a core operator, but rather extending it to work on instances of particular classes. IOW, what you found with your Number class is exactly the way overloading is supposed to work in Perl.

the lowliest monk

  • Comment on Re: overloading core function and non-existing operator

Replies are listed 'Best First'.
Re^2: overloading core function and non-existing operator
by pg (Canon) on Aug 07, 2005 at 22:53 UTC

    Just want to let my mind fly freely for a moment, with Perl and yet not ...

    Say it is more consistent, and main scope itself is also a package just like any other package. Will that help to make ++ overloadable in main? My answer to myself was probably no, as the other side of this issue, probably a more important one is not about scope, but about "native data type". Even if you can overload with main scope, it makes sense not to let one overload operators against native data type, for example scalar.

      and main scope itself is also a package just like any other package. Will that help to make ++ overloadable in main?

      sure, if you see it that way... you just have to bless your variable, just like you did with your Number-package.

      use overload ...; my $n = bless {number => 23}, "main"; print $n >> 2;
      i think that's not what you want, just wanted to make clear that it's not a problem of the package name but that you must have a blessed object.