Is there a standard way to code a module to hold global application parameters to be included in every other package? For instance: use Config;?
A simple package that only contains our variables? What about readonly variables?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s already a standard Config module, so choose a different name.
Say you have
MyConfig.pmwith the following contents:Then other modules might use it as in
If you don’t want to fully qualify the names, then use the standard Exporter module instead.
Add three lines to
MyConfig.pm:Now the full package name is no longer necessary:
You could add a read-only scalar to
MyConfig.pmwithThis is documented in perlmod.
After adding it to
@MyConfig::EXPORT, you might tryin a different module, but you’ll get
As an alternative, you could declare in
MyConfig.pmconstants using the constant module and then export those.