in reply to Crazy constant question...
#!/usr/bin/perl use strict; use warnings; my @num_to_name; BEGIN { @num_to_name = qw(FOO BAR); eval "use constant $num_to_name[$_] => $_" for 0 .. $#num_to_name; } print "FOO-->", FOO(), "-->", $num_to_name[FOO];
I've assumed your names are necessarily 1:1 and adjacent integers starting at 0 - this is what your code seems to do. You could do something with hashes instead for more flexibility.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Crazy constant question...
by ikegami (Patriarch) on Dec 15, 2010 at 21:08 UTC |