in reply to Trying to understand the 'use constant' pragma
XML::Simple (or any of the XML:: family modules) will treat xml files as text. There is no attempt to evaluate perl expressions within that text.
You may be able to handle this as a special case with eval,
Constants from constant.pm are really subs with an empty prototype, so you may need to append '()' or even write ${\LOG_DEBUG()} to get the evaluation done in a quoted string.# notional dereference, use whatever is correct for your xml struct $xml->{'Level'} = eval $xml->{'Level'};
In this case, it might be simpler to do a substitution.
my %level = { LOG_DEBUG => 0, LOG_INFO => 1, LOG_WARN => 2, LOG_ERROR => 3, ); use constant \%level; # . . . { my $regex = qr/(${\join '|', keys %level})/; s/$regex/$level{$1}/g; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to understand the 'use constant' pragma
by webengr (Pilgrim) on Sep 07, 2005 at 02:38 UTC |