in reply to Re^2: 2*pi*$r -- constant function without prototype
in thread 2*pi*$r -- constant function without prototype
Perl Best Practices recommends Readonly. While constants with use constant are replaced at compile time, Readonly variables are normal variables, just set read-only.
The problem with use constant is that the constants are actual functions which don't interpolate in strings!
The problem with use constant is that the constants are actual functions which don't interpolate in strings!
I recently needed the line feed ("\012") as constant (Note: "\n" is platform dependent!).
Compare:
The speed penalty for Readonly is not meaningful in my case. However if you have large calculations which only dependent on constants, maybe inside a loop, then use constant is better because perl can optimise it at compile time.use Readonly; Readonly $NL => "\012"; [...] print FILE "header1${NL}header2${NL}"; use constant NL => "\012"; [...] print FILE "header1" . NL . "header2" . NL;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: 2*pi*$r -- constant function without prototype
by BrowserUk (Patriarch) on May 01, 2008 at 13:53 UTC | |
by parv (Vicar) on May 01, 2008 at 22:57 UTC |
In Section
Meditations