in reply to Why does $$self++ works?

Why is it possible to use an object as a counter?

You are not using the object as a counter but the de-reference of the object. $self is the object but it's also a reference to a scalar (since that's how you have constructed it). When you de-reference the object therefore you get a scalar and so $$self++ is incrementing the scalar. Since the example you mentioned starts with $active = 0, that's the value from which you will be incrementing.

Replies are listed 'Best First'.
Re^2: Why does $$self++ work?
by ikegami (Patriarch) on Sep 29, 2018 at 07:14 UTC

    You are not using the object as a counter but the de-reference of the object

    The OP --not you-- has the correct terminology. The thing referenced is the object --the thing that is blessed-- not the reference.

    The code in question does indeed increment the object, which is unusually a scalar instead of a hash.

Re^2: Why does $$self++ work?
by rob25 (Initiate) on Sep 28, 2018 at 10:10 UTC

    Thanks to point me to the usage of $active in the constructor! By passing it as a reference, it is the scalar I access while dereferencing $self.
    Now, as understand whats going on, I will try to use this approach in my implementation, and see wether there will be a notable performance improvement. :-)