I managed myself to put that into a variable $config using the JSON module. Now, this is the portion of code that's not working.{ "services": [ { "service": "serviceName1", "site": "www.example1.com", "uri": "http://www.url.com/index.html", "option": [ { "name": "option-a", "server": "server-a", "servers": ["server-a1", "server-a2", "server-a3", + "server-a4", "server-a5", "server-b6"] }, { "name": "option-b", "lbvserver": "server-b", "servers": ["server-b1", "server-b2", "server-b3", + "server-b4", "server-b5", "server-b6"] } ] }, { "service": "serviceName2", "site": "www.example2.com", "uri": "http://www.url2.com/index.html", "option": [ { "name": "option-a", "server": "server-a", "servers": ["server-a1", "server-a2", "server-a3", + "server-a4", "server-a5", "server-b6"] }, { "name": "option-b", "lbvserver": "server-b", "servers": ["server-b1", "server-b2", "server-b3", + "server-b4", "server-b5", "server-b6"] } ] } ] }
I don't want to actually print "serviceName1", or "serviceName2". I'm trying to get to the "servers" key inside "option". The thing is that I'm missing something. When i run this, i get thismy @service = $config->{'services'}; foreach $oneservice (@service){ print $oneservice{'service'}; }
I've read a lot about iterating on hashes and arrays, but I'm blocked by the complexity of the JSON. Why it tells me about %oneservice if I declared it as $oneservice?Global symbol "%oneservice" requires explicit package name at ./script +.pl line 102. Execution of ./script.pl aborted due to compilation errors
In reply to Iterate over complex JSON by Northwood128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |