I’m writing an app in Perl with several modules. I want to write some global constants that will be visible from everywhere, like this:
#Constants.pm $h0 = 0; $scale = 20;
And then use them without qualifying with main:: or Constants:: in several modules. However, if I write use Constants; in more than one module, they only get imported into one namespace. Is there any way around this?
I’m using the latest ActivePerl.
You can put this at the top of
Constants.pm:In this case all the variables you define will be in the
mainnamespace:or if you’re feeling brave:
In this case all the variables you define will be in an empty namespace:
Note that using
packagewith no namespace is discouraged, and will apparently be deprecated in some versions of Perl. See the quote below.Quoting from
man perlfunc:Edit: This question might be helpful as well: How do I use constants from a Perl module?