Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2016-10-01 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (579 votes). Check out past polls.