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,

# notional dereference, use whatever is correct for your xml struct $xml->{'Level'} = eval $xml->{'Level'};
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.

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
    Thanks Zaxo, I will try this. I probably wouldn't do it in production code, but for the sake of followint through on my exercise I will take a few more whacks at it. Thanks to everyone who responded!
    PCS