For the record, your proposed refactoring of the data structure wouldn't work in my case because 'Locations' is one key of many at the top level. The whole structure is intended to represent an empire, which controls a set of locations, has various technologies, a name, etc. Some of those are simple values, some are themselves nested structures. A 'Location' (identified by a name) has a set of buildings, but also resources, a description, an inventory, etc. So simplifying things in the manner you suggest would result in Locations colliding with the strings 'Name', 'Technologies', etc.
As for dereferences taking time -- um, my module uses a hash tie, and on every lookup it splits apart the key and does a recursive lookup. So it's far, far slower than just a set of dereferences! Performance is really not a concern. This is an exploration into readability.
But your comment about keys suggests that you misunderstand what I'm doing. The actual data structure is merely a HoHoHo...H. I am never storing any keys in their dotted form. Doing so would prevent me from grabbing out pieces of the structure:
I am just providing a hash reference that, in addition to being addressable the normal way, can also be addressed with an alternate dotted syntax. The internal structure is unchanged, and a deterministic traversal just requires a regular ASCIIbetical sort of the keys at each level (same as any other HoH.)$location_info = $h->{"Locations.$location"}; print "$location description: $location_info->{Description}\n";
Sorry if this wasn't clear from the original post.
In reply to Re^4: Dotted hash access
by sfink
in thread Dotted hash access
by sfink
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |