in reply to Are "use constant" constants really inlined?

Hello Darkwing,

Yes, B::Deparse shows that they are indeed inlined:

17:21 >perl -MO=Deparse -e "use constant { C => 42, D => 0 }; print C; + print 'Debug' if D;" use constant ({'C', 42, 'D', 0}); print 42; '???'; -e syntax OK 17:28 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Are "use constant" constants really inlined?
by ikegami (Patriarch) on Jun 30, 2016 at 18:27 UTC

    B::Concise is even more definitive since it shows very accurate information about the opcodes (whereas B::Deparse synthesizes a Perl code approximation).

    $ perl -MO=Concise,-exec -e'use constant { C => 42 }; print C;' 1 <0> enter 2 <;> nextstate(main 187 -e:1) v:{ 3 <0> pushmark s 4 <$> const[IV 42] s*/FOLD 5 <@> print vK 6 <@> leave[1 ref] vKP/REFC -e syntax OK

    Compare to a sub call:

    $ perl -MO=Concise,-exec -e'sub C { 42 } print C;' 1 <0> enter 2 <;> nextstate(main 3 -e:1) v:{ 3 <0> pushmark s 4 <0> pushmark s 5 <#> gv[IV \] s 6 <1> entersub lKS 7 <@> print vK 8 <@> leave[1 ref] vKP/REFC -e syntax OK
Re^2: Are "use constant" constants really inlined?
by Darkwing (Scribe) on Jun 30, 2016 at 07:47 UTC
    Thanks, and B::Deparse is an interesting module; didn't know that.