Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Are "use constant" constants really inlined?

by haukex (Archbishop)
on Jun 30, 2016 at 07:30 UTC ( [id://1166918]=note: print w/replies, xml ) Need Help??


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

Hi Darkwing,

From "Constant Functions" in perlsub (emphasis mine):

Functions with a prototype of () are potential candidates for inlining. If the result after optimization and constant folding is either a constant or a lexically-scoped scalar which has no other references, then it will be used in place of function calls made without &.

The documentation then goes on to show an example like the one you're asking about (note that use constant ... in the main program essentially causes the module to be executed inside a BEGIN block in the main program, see use).

Athanasius already showed how to use B::Deparse to check if they are inlined.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Are "use constant" constants really inlined?
by Darkwing (Beadle) on Jun 30, 2016 at 07:51 UTC
    Thanks!

    "a lexically-scoped scalar which has no other references,"

    This makes it clear. In fact, i looked into the docu, but read it too briefly so i missed this sentence!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found