Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://913424]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-26 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found