in reply to Re: indirect/symbolic access in perl
in thread indirect/symbolic access in perl
This ugly code below does work:
but I hate evals, and you would be much better served by using something like#use strict; use Readonly; my @EXPORTS=qw(DBG_ONE DBG_TWO DBG_FOUR); Readonly::Scalar my $DBG_ONE => 1; Readonly::Scalar my $DBG_TWO => 2; Readonly::Scalar my $DBG_FOUR => 4; foreach my $flag (@EXPORTS) { printf "flag = %s, value = 0x%04x\n", $flag, eval( "\$" . $flag ); }
Update:bruceb3's code works fine. Ignore the code I posted, which is essentially identical to bruceb3's but uses eval (and thus avoids conflict with "use strict 'refs'). Do follow the advice regarding using a Readonly HASH - much safer, and probably closer to what you need to do.Readonly::Hash my %DBG_Val => (DBG_ONE => 1, DBG_TWO => 2, DBG_FOU +R =>4);
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: indirect/symbolic access in perl
by perl-diddler (Chaplain) on Sep 20, 2007 at 17:03 UTC |