in reply to weaken CODEREF
However, as an optimisation (with unfortunately visible side effects), if that CV isn't closing over any outer lexicals, the CV isn't copied, it's shared: so its ref count is bumped and a new reference to it is returned. Which is what you're seeing here.
The other common visible side-effect is this:
for (1,2) { push @a, sub {}; my $lex; push @b, sub { $lex }; } bless $a[0]; bless $b[0]; print "$a[1] $b[1]\n";
which outputs
main=CODE(0x1f41648) CODE(0x1f40c88)
Whoops, $a[1] is blessed too.
No-ones thought of a way round this yet, but removing the optimisation would make simple anon subs a lot slower.
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: weaken CODEREF
by tobyink (Canon) on Nov 11, 2013 at 13:07 UTC |