shemp has asked for the wisdom of the Perl Monks concerning the following question:
Anyway, sometimes i'll want to use the same constants across many of these required libraries. Is the best way to do this to create a package with all the constants in it, export them, and use the constants package in all the support libraries that need them?
I guess this method seems a bit cluttered. Heres a simple example:
# file MyConstants.pm
# file my_program.plpackage MyConstants; require Exporter; use base qw(Exporter); @EXPORT = qw(C1 C2); use constant C1 => 'blah'; use constant C2 => 'foo'; 1;
# file my_support_lib.pl#!/usr/bin/perl use MyConstants.pm require 'my_support_lib.pl'; ... # do something with the constants from MyConstants.pm ...
Is this a good way to accomplish this sort of thing?... use MyConstants.pm; ... # do something with the constants from MyConstants.pm ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: constants in multiple libraries
by davorg (Chancellor) on Sep 17, 2004 at 16:24 UTC | |
|
Re: constants in multiple libraries
by JediWizard (Deacon) on Sep 17, 2004 at 16:45 UTC | |
by shemp (Deacon) on Sep 17, 2004 at 20:58 UTC | |
by JediWizard (Deacon) on Sep 20, 2004 at 14:23 UTC | |
|
Re: constants in multiple libraries
by ikegami (Patriarch) on Sep 17, 2004 at 16:31 UTC | |
by shemp (Deacon) on Sep 17, 2004 at 16:41 UTC |