http://www.perlmonks.org?node_id=1116729


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