rpaskudniak has asked for the wisdom of the Perl Monks concerning the following question:
I could not think of a way to search this or any other forum/search engine for a question like this.
I have a configuration file that contains fields that are actually the of "fields" in a hash. (Actually a json hash but that's besides the issue at hand.) These will correspond with positional parameters supplied at run-time. For example, here re a couple of lines; each is a set of fields, comma separated:
(I do need to protect the private data of my client.)name,address-virtual-email movie-role,hoig-boig-loig-shmoig
The first line requires that I plunk a value into:
The second line tells to plunk run-time values intoo $js->{name} # This is the easy part o $js->{address}{virtual}{email} # Here's the trouble
There are dozens of such lines in the config file and there's no telling what they will add to the list. So I'm racking my brains out for a way to address the substructures (using the term loosely) in a dynamic fashion. I can certainly combine the string $compound = "{hoig}{boig}{loig}{shmoig}" but it won't help me to address js=>{$compound} because that is just a string and there is no such key in the hash.o $js->{movie}{role} # In this example o $js->{hoig}{boig}{loig}{shmoig} # both are trouble!
Can anyone come up with a way to get at the nested fields in the hash when I can't know in advance which keys (and sub-keys) I will need to address? I don't believe the symbol table will help here; the keys of the hash (and all its sub-hashes) are not in the symbol table (I think).
Thanks! Gracias! Spasiba! Szepem Köszönöm!
-- RP
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Dynamic addressing in a hash
by hv (Prior) on Sep 01, 2022 at 00:16 UTC | |
by rpaskudniak (Novice) on Sep 01, 2022 at 03:07 UTC | |
by hv (Prior) on Sep 01, 2022 at 10:11 UTC | |
by rpaskudniak (Novice) on Sep 01, 2022 at 13:19 UTC | |
by AnomalousMonk (Archbishop) on Sep 01, 2022 at 04:00 UTC | |
by rpaskudniak (Novice) on Sep 01, 2022 at 17:20 UTC | |
Re: Dynamic addressing in a hash
by GrandFather (Saint) on Sep 01, 2022 at 02:20 UTC | |
Re: Dynamic addressing in a hash
by AnomalousMonk (Archbishop) on Sep 01, 2022 at 01:40 UTC | |
Re: Dynamic addressing in a hash
by LanX (Saint) on Sep 01, 2022 at 01:33 UTC | |
by LanX (Saint) on Sep 01, 2022 at 02:08 UTC |