Right off the bat, the docs are unclear. Other than which reference? The pad's?
And then there's the issue that my $lex; produces a lexical var, but isn't one itself. Does that matter?
Control:
>type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" sub with_proto() { 4 } sub without_proto { 4 } with_proto(); without_proto(); <---- Note absence of "with_proto" 5 <#> gv[*without_proto] s <---- Not constant
Tests:
>type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" sub with_proto() { my $lex } sub without_proto { my $lex } with_proto(); without_proto(); 4 <#> gv[*with_proto] s <---- Not constant 8 <#> gv[*without_proto] s <---- Not constant >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" my $lex = 4; sub with_proto() { $lex } sub without_proto { $lex } with_proto(); without_proto(); 8 <#> gv[*with_proto] s <---- Not constant c <#> gv[*without_proto] s <---- Not constant >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" { my $lex = 4; sub with_proto() { $lex } } { my $lex = 4; sub without_proto { $lex } } with_proto(); without_proto(); i <#> gv[*with_proto] s <---- Not constant m <#> gv[*without_proto] s <---- Not constant
Bah, let's try references.
>type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" sub with_proto() { \my $lex } sub without_proto { \my $lex } with_proto(); without_proto(); 4 <#> gv[*with_proto] s <---- Not constant 8 <#> gv[*without_proto] s <---- Not constant >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" my $lex = 4; sub with_proto() { \$lex } sub without_proto { \$lex } with_proto(); without_proto(); 8 <#> gv[*with_proto] s <---- Not constant c <#> gv[*without_proto] s <---- Not constant >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" { my $lex = 4; sub with_proto() { \$lex } } { my $lex = 4; sub without_proto { \$lex } } with_proto(); without_proto(); i <#> gv[*with_proto] s <---- Not constant m <#> gv[*without_proto] s <---- Not constant
lvalue?
>type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" sub with_proto() :lvalue { my $lex } sub without_proto :lvalue { my $lex } with_proto(); without_proto(); 4 <#> gv[*with_proto] s 8 <#> gv[*without_proto] s >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" my $lex = 4; sub with_proto() :lvalue { $lex } sub without_proto :lvalue { $lex } with_proto(); without_proto(); 8 <#> gv[*with_proto] s c <#> gv[*without_proto] s >type test.pl && perl -MO=Concise,-exec test.pl 2>&1 | find "proto" { my $lex = 4; sub with_proto() :lvalue { $lex } } { my $lex = 4; sub without_proto :lvalue { $lex } } with_proto(); without_proto(); i <#> gv[*with_proto] s m <#> gv[*without_proto] s
No more ideas.
In reply to Re: Inlining a "lexically-scoped scalar which has no other references"
by ikegami
in thread Inlining a "lexically-scoped scalar which has no other references"
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |