in reply to Re^5: Constant names come into conflict with Perl style?
in thread Constant names come into conflict with Perl style?
What you will see more of is the constant declarator. Just put "constant" where you would have put "my", like this:
This declares a true compile-time constant, lexically scoped. Any place the compiler sees $foo, it's free to substitute in 12. The item declared need not have a sigil on the front as long as it's a valid identifier:constant $foo = 12;
That just makes it a bit harder to interpolate. Instead of $foo you'd have to say {foo}. But any valid identifier also includes Unicode, so you can even say:constant Int foo = 12;
constant Num π = atan(2,2) * 4;
Note that the expression is evaluated at compile time, whereas readonly on a normal my evaluates at run time.
|
|---|