|Just another Perl shrine|
Crazy constant question...by pileofrogs (Priest)
|on Dec 15, 2010 at 20:37 UTC||Need Help??|
pileofrogs has asked for the
wisdom of the Perl Monks concerning the following question:
This question is probably more trouble than it's worth, but it's been bugging me, so here goes:
I can create constants like so:
but if I want a way to convert the number back into a string, I need to do something that defines the same relationships again, like
which allows me to do things like:
My problem is, I hate that I have to maintain my constant declarations and my @num_to_name list separately. If I was doing this with a large number of constants, I'd screw it up for sure.
I actually made a thing that sort of does what I want, though It's cludge-tastic and probably all wrong and unnecessarily stupid:
With that monster, $num_to_name[FOO] eq 'FOO' no matter what. It loses the inlining of use constant, which is part of what's lame about it.
Is there a way to do this that sucks less?
Thank you for your indulgence