Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: How to interpolate CONSTANTS in Here docs?

by BrowserUk (Patriarch)
on Feb 14, 2015 at 21:12 UTC ( [id://1116729]=note: print w/replies, xml ) Need Help??


in reply to Re: How to interpolate CONSTANTS in Here docs?
in thread How to interpolate CONSTANTS in Here docs?

It might be noteworthy that Conway's Perl Best Practices recommends against constant,

Grrr. That damn book has done infinitely more harm than good. (As predicted!)

It completely misses the point of constant; namely that it works with Perl to optimise your code.

Because constants are defined as invariant subroutines, Perl can optimise away whole chunks of code at compile time:

C:\test>perl -MO=Deparse -Mconstant=DEBUG,1 -le"print 'hi'; DEBUG and +print 'here'; print 'bye'" BEGIN { $/ = "\n"; $\ = "\n"; } use constant (split(/,/, 'DEBUG,1', 0)); print 'hi'; print 'here'; ## When DEBUG is defined; it doesn't need to be teste +d for at runtime. (No conditional!) print 'bye'; -e syntax OK C:\test>perl -MO=Deparse -Mconstant=DEBUG,0 -le"print 'hi'; DEBUG and +print 'here'; print 'bye'" BEGIN { $/ = "\n"; $\ = "\n"; } use constant (split(/,/, 'DEBUG,0', 0)); print 'hi'; '???'; ## And when it's not; both the conditional and the cod +e it controls are simply optimised away. print 'bye'; -e syntax OK

Write-once variables are a piss poor substitute; an anathema to Perl; and an abomination.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^3: How to interpolate CONSTANTS in Here docs?
by shmem (Chancellor) on Feb 14, 2015 at 21:44 UTC
    That damn book has done infinitely more harm than good. (As predicted!)

    I can't gainsay; and I wouldn't if I could.

    Write-once variables are a piss poor substitute; an anathema to Perl; and an abomination.

    True, true and true. We would upvote all of this if I were four of me.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-18 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found