in reply to Re^3: References for ano subs fixed at compile time? (nope)
in thread References for ano subs fixed at compile time?

You missed the point, the different calls to sub {1} print different refs, even that 1 is always the same code and not a closed over var.

The reason is that sub {2} reused the first ref and $b inhibits its release!

DB<161> ;{ my $b; for (1..3){ print sub {1} ; print $b= sub {2} if $ +_==1 } } CODE(0x86c5af0) CODE(0x86c5af0) CODE(0x86c5be0) CODE(0x86c5be0) DB<163> ;{ my $b; for (1..3){ print 0+sub {1} ; print 0+($b= sub {2} +) if $_==1 } } 141319216 141319216 141319552 141319552

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^5: References for ano subs fixed at compile time? (opnode)
by tye (Sage) on Jun 18, 2013 at 22:59 UTC

    Well, that part is the stupider part. If address X is no longer used, it is obvious that address X might be re-used. If address X gets re-used, it is obvious that it might still be being used and so can't be re-used a third time.

    But, indeed, even completely identical code refs get recreated each time in my version of Perl (so I lose my bet). Which probably means that a closure is generated even if nothing got closed over.

    But each closure contains a pointer to the code that got compiled for that (trivial) sub. Perhaps that is what you want?

    - tye        

      > Perhaps that is what you want?

      I thought I could use the code-ref as reliable identifier for the call position ( not just the line-number caller provides ).

      Something which can be used to emulate position dependent built-ins like the flip-flop operator.

      I tried B::svref_2object but the docs to B are somehow cryptic...

      Cheers Rolf

      ( addicted to the Perl Programming Language)