Test::Deep::cmp_deeply
是否有一个现成的 Perl 模块可以扫描任意大的散列和数组嵌套结构并用仅引用单个值替换所有相同的分支(例如,会说“ok”的分支)?
对于这个问题,我已经有了自己的解决方案,但如果可用的话,我更愿意使用现有的快速 XS 模块。
Data::Dumper所示的原始结构示例:
$VAR1 = {
'other_elems' => [
{
'sub_elements' => [
{'id' => 333},
{
'props' => ['attr5', 'attr6'],
'id' => 444
}
],
'other_key_for_attrs' => ['attr1', 'attr5'],
'id' => 222
},
{
'sub_elements' => [{'id' => 333}],
'id' => 111
}
],
'elems' => [
{
'attrs' => ['attr1', 'attr5'],
'id' => 1
},
{
'parent' => 3,
'attrs' => ['attr1', 'attr5'],
'id' => 2
},
{
'attrs' => ['attr5', 'attr6'],
'id' => 3
},
{
'attrs' => ['attr5', 'attr6'],
'id' => 4
}
]
};
预期结果结构示例:
$VAR1 = {
'other_elems' => [
{
'sub_elements' => [
{'id' => 333},
{
'props' => ['attr5', 'attr6'],
'id' => 444
}
],
'other_key_for_attrs' => ['attr1', 'attr5'],
'id' => 222
},
{
'sub_elements' =>
[$VAR1->{'other_elems'}[0]{'sub_elements'}[0]],
'id' => 111
}
],
'elems' => [
{
'attrs' => $VAR1->{'other_elems'}[0]{'other_key_for_attrs'},
'id' => 1
},
{
'parent' => 3,
'attrs' => $VAR1->{'other_elems'}[0]{'other_key_for_attrs'},
'id' => 2
},
{
'attrs' =>
$VAR1->{'other_elems'}[0]{'sub_elements'}[1]{'props'},
'id' => 3
},
{
'attrs' =>
$VAR1->{'other_elems'}[0]{'sub_elements'}[1]{'props'},
'id' => 4
}
]
};