Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 perusing the Monastery: (7)
As of 2014-09-16 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (11 votes), past polls