see perlsub#Constant-Functions
sub aa(){2} sub bb(){2} my ($a, $b) = (aa, bb); my ($s, $t) = ((2*aa+bb), (2*$a+$b)); say STDERR "$a==", aa; say STDERR "$b==", bb; say STDERR "$s==$t";
2==2 2==2 6==6
Otherwise - as others already pointed out - arguments will be swallowed.
Additionally you'll suffer of a performance penalty because constant subs are not called but inlined.
Keep in mind that + is likewise a binary and unary operator, i.e. interpretation depends on context and might not DWYM.
See constant.pm for an easy way to declare most constants.
And others prefer Readonly.pm to avoid the ambiguities of barewords.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re: Constant code (prototype)
by LanX
in thread Constant code
by philiprbrenan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |