Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: unknown number of dimensions of a multidimensional hash

by GrandFather (Sage)
on Mar 09, 2006 at 23:22 UTC ( #535554=note: print w/replies, xml ) Need Help??


in reply to unknown number of dimensions of a multidimensional hash

The following code is taken from a game engine and manipulates "keys" of the form (\w+\.)+\w+. Each word represents a hash level.

our %GameState; # The entire game context # looks up a key (passed as the first param) and adds the value # (if provided as second param). Returns a reference to the value # list. sub Entity { my ($key, $value) = @_; return undef if ! defined $key; my $hash = \%GameGlobals::GameState; my @keys = split /\./, $key; map {$_ = lc $_} @keys; while (@keys && defined $hash) { my $key = shift @keys; if (@keys) { $hash->{$key} = {} if ! exists $hash->{$key}; $hash = $hash->{$key}; } else { $hash->{$key} = [] if ! exists $hash->{$key}; push @{$hash->{$key}}, $_[1] if defined $value; return \$hash->{$key}; } } }

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://535554]
help
Chatterbox?
[LanX]: yeah whatever ... I'm in the favorable condition to already autohiding him ... how can I judge the poor FOOLs who still see his contributions xD
[Eily]: he's been pretty saavy about threads that were implictly about him in the past. I think he might have deliberatly avoiding mentioning it for some reason (he got tired?)
[Eily]: he did mention one of his propositions: basically make it possible to ignore downvotes, by separating them more from the upvotes
Eily translate("Eilish ", "Proper English")

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-07-24 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (356 votes). Check out past polls.