bfreemer has asked for the wisdom of the Perl Monks concerning the following question:
I know symbolic references are universally frowned upon, but I am adapting an existing program where I think it is necessary.
I would like to do something like the following:
# The following line is the re-existing code in another # part of the program beyond my control: # $alpha_state = "STATE"; # Next follows my own code: use strict; my %hash; $hash{alpha}{state} = ${"$alpha" . "_state"};
Obviously the last line is not correct and I get the "Can't use string ... as scalar ref..." warning. In essence, I want the hash value $hash{alpha}{state} to always equal $alpha_state.
I've tried lots of permutations and hard references as well as re-reading the documentation on symbolic references, but can't quite figure this out. Any tips? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mandatory Symbolic References?
by tilly (Archbishop) on Jan 18, 2011 at 20:11 UTC | |
|
Re: Mandatory Symbolic References?
by JavaFan (Canon) on Jan 19, 2011 at 09:43 UTC | |
|
Re: Mandatory Symbolic References?
by ELISHEVA (Prior) on Jan 18, 2011 at 21:06 UTC | |
by Anonyrnous Monk (Hermit) on Jan 18, 2011 at 21:35 UTC | |
by ELISHEVA (Prior) on Jan 18, 2011 at 21:46 UTC | |
|
Re: Mandatory Symbolic References?
by JavaFan (Canon) on Jan 19, 2011 at 02:13 UTC |