Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Storing an indeterminate number of hash keys in a variable

by state-o-dis-array (Hermit)
on Jul 08, 2011 at 20:51 UTC ( #913424=note: print w/replies, xml ) Need Help??


in reply to Storing an indeterminate number of hash keys in a variable

There's probably a better way to do it, but you could do something along the lines of:
my %test; $test{a}{b}{c}{d} = "Hi"; my @keys = qw( a b c d ); my $out; my $ref = \%test; for( @keys ){ if( ref $ref->{$_} eq 'HASH' ){ $ref = \%{$ref->{$_}}; } else{ $out = $ref->{$_}; } } print "$out\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://913424]
help
Chatterbox?
marioroy I once fell asleep while drive and had no collection on how I exited the ramp. Then called my wife not knowing where I was totally lost.
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-29 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?