in reply to Re^8: "my" declaration problem
in thread "my" declaration problem

How is it possible that $atexit holds 2 objects which are both destroyed at scopes end?

Even if this somehow works, then it's highly implementation dependent and could break in a future Perl version.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^10: "my" declaration problem
by shmem (Chancellor) on Apr 25, 2017 at 21:50 UTC
    How is it possible that $atexit holds 2 objects which are both destroyed at scopes end?

    Because there are 2 $atexit variables - a masked one, and a masking one created later.

    This is all to fullfill what hath been written:

    "my" variable $var masks earlier declaration in same scope

    Since it masks that variable - and does not replace it since this would mean destroying the current my variable of that name, the scope of the masked variable ends when the masking ends - because the scope of the masking variable ends - which is: at scope end.

    IMHO this is not an implementation specific detail, but part of the the design of my and perl scopes, thus part of the language.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^10: "my" declaration problem
by Corion (Patriarch) on Apr 25, 2017 at 21:20 UTC

    I think this works because lexical variables are only cleaned up at the end of their scope, as every lexical variable ends up in the CvPADLIST structure (cf. pad.c and perlintern where I found this). The CvPADLIST is an array and not a hash, as far as I understand it.

    Please provide an example where the code is not broken.

    I showed what you requested, an example where the code is demonstrably not broken.

      > an example where the code is demonstrably not broken.

      yes you did, thank you!

      But my opinion holds, for me this depends too much on implementation details.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        You are always entitled to your opinion. ENJOY! :D
Re^10: "my" declaration problem
by Anonymous Monk on Apr 26, 2017 at 14:34 UTC

    Do not forget the runtime effect of my. See "goto" memory leak. (And maybe this for a lovely show of side effects.)

    Perl cannot and must not destroy objects before their scope ends. Implementation detail is the order in which global objects are destroyed.