Keep It Simple, Stupid | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Ok, so not a fix, but a workaround. The problem is fairly well described in this blog post and this bug report for YAML::XS. The merge keys functionality of YAML is not supported by either YAML::XS or YAML::Syck, so this script:
produces this output:
The expected functionality is for the keys of key1 to be merged into the keys of key2, with key2 taking precedence. Not having the time or resources to dig into the XS guts of either module, my solution was a simple recursion function to traverse the data structure, merging the '<<' references with their containing objects:
This produces the much more accurate data structure:
Obviously, this is not a very robust solution. It makes no checks for cyclical data, potentially expands the data structure due to dereferencing some addresses, and its recursive nature means it would rapidly consume resources when used on very deep data structures. But for the needs that I had, it worked pretty well. Hopefully the maintainers of YAML::XS and YAML::Syck can provide this functionality soon, since it seems that their respective underlying C libraries support merge keys just fine. UPDATE: Found a couple easy ways to avoid recursion. See my reply below.
In reply to A fix for merge keys in YAML::XS, YAML::Syck by bv
|
|