webengr has asked for the wisdom of the Perl Monks concerning the following question:
I'm playing around with "use constant" to better understand the pragma, and I ran into a curiosity question. Here's the scenario:
MyObject.pm defines and exports constants as follows:
and the calling script uses these variables to instantiate an object of type MyObject like this:use Exporter; our @ISA = qw(Exporter); use constant { LOG_DEBUG => 0, LOG_INFO => 1, LOG_WARN => 2, LOG_ERROR => 3, }; our @EXPORT = qw(LOG_DEBUG LOG_INFO LOG_WARN LOG_ERROR);
my $obj = MyObject->new(level=>LOG_DEBUG);
What I can't figure out how to do is specify the parameter in an XML config file, as <Level>LOG_DEBUG</Level>. I'm using XML::Simple to parse the config file, and I wind up with a hash that holds the string "LOG_DEBUG", which is quite different from the constant function LOG_DEBUG.
Is there an easy way to make this work?
I know it's not good practice to export stuff by default, but I'm just playing with a contrived scenario to explore the pragma.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to understand the 'use constant' pragma
by Zaxo (Archbishop) on Sep 06, 2005 at 23:58 UTC | |
by webengr (Pilgrim) on Sep 07, 2005 at 02:38 UTC | |
|
Re: Trying to understand the 'use constant' pragma
by GrandFather (Saint) on Sep 06, 2005 at 23:43 UTC | |
by webengr (Pilgrim) on Sep 07, 2005 at 02:35 UTC | |
|
Re: Trying to understand the 'use constant' pragma
by runrig (Abbot) on Sep 06, 2005 at 23:44 UTC | |
|
Re: Trying to understand the 'use constant' pragma
by phaylon (Curate) on Sep 06, 2005 at 23:46 UTC |