in reply to Re^4: Confusion over scope of "my" vars
in thread Confusion over scope of "my" vars

The reference counter is not neccessarily 0 at the end of the scope

It's never zero at end of scope. At the very least, the pad references the scalar. If the refcount is one at scope exit, the variable is cleared*. If the refcount is greater than one at scope exit, a new SV is created and associated with the variable.

* — Clearing is similar to undefining, but the string buffer isn't cleared.

  • Comment on Re^5: Confusion over scope of "my" vars

Replies are listed 'Best First'.
Re^6: Confusion over scope of "my" vars
by LanX (Saint) on Nov 26, 2008 at 21:14 UTC
    I'm sure the behaviour is well defined and consistent and well thought and I'm trusting it ... but if you say:

    > If the refcount is one at scope exit, the variable is cleared*

    aren't you denying the results of the OT? The scope of the sub is left, only the reference of the pad should be left, but the variable isn't cleared?

    anyway I remember Advanced Perl Programming having a detailed explanation about pads and refcounts. So if you think you don't have a typo in your last post, don't bother explaining to me, what I can easily look up in detail in my bookshelf ... 8 )

    Cheers Rolf

      aren't you denying the results of the OT?

      That was a description of the normal behaviour. To tie it back to the OP, nothing happens on scope exit if the my isn't executed.

        > To tie it back to the OP, nothing happens on scope exit if the my isn't executed.

        Do you know if this is a well defined feature?
        Can't see why undefining a var with minimized ref-counter should be restricted to a previous my-init !(?)

        Cheers Rolf