in reply to Re: Constant Functions
in thread Constant Functions
I was just thinking about this, and a neat idea popped into my head: I gave the speed of light as my example, but I gave it in meters per second. What if I wanted to store that value in a couple formats? I could name it C_MPS or something equivalently useless, but I like simple straight forward names. So I started thinking about namespaces. You could put your collection of constants into a package and then name each function with an appropriate moniker. Don't export any of them, just reference them directly... ie, C::MPS and C::MPH and so on. I suppose you get fancy and write the function C to return C::MPS (or your prefered default) and Export that. Then the user can just call C or C::YPD (yards per day) And since Perl will inline each constant function, you still don't take any usage hit.
| A reply falls below the community's threshold of quality. You may see it by logging in. |