Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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";


Comment on Re: Storing an indeterminate number of hash keys in a variable
Download Code

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 musing on the Monastery: (10)
As of 2015-03-03 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (62 votes), past polls