one of the best ways to make constants in general is using prototyped subroutines (in fact thats one of the only things prototypes are good for). so:
sub PI ()
{ return 3.14 }
or:
sub constantArray ()
{ return ( 4, 5, 6) }
that should do it.
jeff | [reply] [Watch: Dir/Any] [d/l] [select] |
You can also use the "constant" module:
use constant SCALAR_CONST => 3.14159265;
use constant ARRAY_CONST => ( 'This', 'is', 'fun' );
use constant HASH_CONST => ( pi => 3.14159265,
c => 299_792_458 ); # m/s
#etc.
Which actually just creates convenient sub routines for you. ( I prefer this method because it is a little more explicit, plus it is self documenting. ) | [reply] [Watch: Dir/Any] [d/l] |
don't forget about Const, which is similar to what you suggested. This and other interesting tidbits can be found in this node.
BlueLines
Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary. | [reply] [Watch: Dir/Any] |