Subject: | Feature Request: Named Constant Export? |
I like this way of exporting subroutines. I also own and have read the "Perl Best Practices" book (cover to cover, it's good). And I understand the rational for not exporting variables from modules.
However, what about the special case of read-only named constants? For instance, if I have a module of physics constants, and want to use them by name in a calling module. Is using functions instead of constants the only way to do this? $volume = (4/3) * PI() * r^3 leaves one wondering what's wrong in the formula. (4/3) * PhysConst->PI() * r^3 is worse. Of course, if someone wrote '$PI = 22/7;' a read only variable should complain (legal statutes aside!). Many more meaningful situations come to mind like named logging levels, month names, roman numerals. Essentially anything that might be an unchanging name/value pair. I have no idea how such a thing could be implemented, and the whole point is, of course, to dump these variables in to the namespace of the caller. Keeping them localized to just where they are wanted seems impossible, but still the benefits of named consistent named constants seems greater.
Thanks,
Stuart R. Jefferys
(PhD student, UNC-Chapel Hill, Genetics curriculum and Bioinformatics)