in reply to Re: Re: Re: Runtime Hash Variable access
in thread Runtime Hash Variable access
What I was doing in my reply is called a sumbolic reference?
Symbolic, yes.
And that is deprecated?
No, just frowned upon.
I think it's quite a nice way of getting the value of a variable which name you don't yet know.
It's not. It requires global variables, which suck (see Coping with Scoping) and makes debugging hard. Instead, just use a hash (forget for a moment that the stash is a hash, if you knew that). Your code, using a hash and strict, would be:
See also Why it's stupid to `use a variable as a variable name'.use strict; my %hash; $hash{the_var_i_want} = "this is the actual value I want to get"; my $the_name = <STDIN>; #say, this would be "the_var\n" chomp $the_name; print $hash{"${the_name}_i_want"};
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
---|