the docu of constant says that constants such as
are inlined. In constant.pm, the corresponding lines of code are:use constant DEBUG => 0;
But here, a local variable is defined and then used within a sub defined in this block. This should result in a closure rather than in an inlinable subroutine: whenever this block is executed, a new $scalar variable is created and it won't be removed since the subroutine accesses it. So, i understand closures to work. But then the body of the sub isn't a constant value, it is a variable, and so it should not result in an inlinable constant.... if (@_ == 1) { my $scalar = $_[0]; *{"${pkg}::$name"} = sub () { $scalar }; } ...
Well, i'm wrong? Are those constants really inlined? Bit if so, why does it work? Why aren't they closures?
In reply to Are "use constant" constants really inlined? by Darkwing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |