Perl Monk, Perl Meditation | |
PerlMonks |
Re^3: Convert string to hashby 1nickt (Canon) |
on Mar 27, 2017 at 17:59 UTC ( [id://1186107]=note: print w/replies, xml ) | Need Help?? |
Building on AppleFritter's answers: You can combine the loop through your results with the hash-building using map, which transforms one list into another, while performing some action on each element. In this case the action would be to add the appropriate key and value to your hash. (And we can transform the first list into a hash because a hash is a list of pairs ...) Here map takes each element of the list returned by values(), which is a hashref, extracts the value of its key 'certname', uses that as the key in the new hash, and uses the entire hashref as the value. Also note that I dereferenced the hashref $json_hash{'results'} before using it, because it's not "stable" Perl code to call values() (or keys()) on a hashref. I imagine you got a warning like "values on reference is experimental at ...", no? Hope this helps!
The way forward always starts with a minimal test.
In Section
Seekers of Perl Wisdom
|
|