我正在尝试使用
XML :: Dumper序列化以下数据结构
'options_settings' => { 'telnet.distinct.enable' => { 'text' => 'Option telnet.distinct.enable needs to be set to \'on\' as of workaround for Bug 476803','severity' => '7' } },'EOS_details' => { '338' => bless( { 'info' => '<a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank"> CPC-0705-02 </a>','count' => '48','ASUP_id' => 'AE20121117202086','part' => 'ESH2 - X5511A-RC,X5511-RC-C','category' => 'I/O Module','EOS_date' => '06/02/2013','severity' => '8' },'EOSObject' ),
问题是当我用XML解析它到xml:Dumper它使用相同的内存地址进行2个单独的哈希引用:
<item key="338"> <hashref blessed_package="EOSObject" memory_address="0x295b5758"> <item key="ASUP_id">AE20121117165273</item> <item key="EOS_date">06/02/2013</item> <item key="category">I/O Module</item> <item key="count">48</item> <item key="info"><a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank"> CPC-0705-02 </a></item> <item key="part">ESH2 - X5511A-RC,X5511-RC-C</item> <item key="severity">8</item> </hashref> </item> </hashref> <item key="options_settings"> <hashref memory_address="0x295b5320"> <item key="telnet.distinct.enable"> <hashref memory_address="0x295b5758"> </hashref> </item> </hashref> </item>
请注意memory_address =“0x295b5758”.
因此,当从文件读回时,option_settings哈希引用指向EOS对象:/
这是XML :: Dumper中的错误还是我做错了什么?使用最新的XML :: Dumper 0.81
附:
我试图在主脚本之外重现它,它的工作原理.
我仍然无法理解主脚本中数据是如何被破坏的.
这是使用XML :: Dumper的代码:
DEBUG("Before serialization: " . Data::Dumper::Dumper($result)); my $dump = new XML::Dumper; my $dump_test = new XML::Dumper; my $test_xml = $dump_test->pl2xml ($result); DEBUG("After serialization in memory: " . Data::Dumper::Dumper($test_xml)); $dump->pl2xml( $result,$filename );
结果打印正确. “options_settings”是单独的条目.在$test_xml中,它已经与EOS_details混淆了
解决方法
我试图复制你的问题而没有任何成功.
#!/usr/bin/perl -Tw use strict; use warnings; use XML::Dumper; my $eos = bless { 'info' => '<a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank"> CPC-0705-02 </a>','count' => '48','ASUP_id' => 'AE20121117202086','part' => 'ESH2 - X5511A-RC,'severity' => '8' },'EOSObject'; my %data = ( 'options_settings' => { 'telnet.distinct.enable' => { 'text' => 'Option telnet.distinct.enable needs to be set to \'on\' as of workaround for Bug 476803','severity' => '7' } },'EOS_details' => { 338 => $eos } ); print pl2xml( \%data );
我的程序的输出:
<perldata> <hashref memory_address="0x253fb18"> <item key="EOS_details"> <hashref memory_address="0x2517e08"> <item key="338"> <hashref blessed_package="EOSObject" memory_address="0x24f9998"> <item key="ASUP_id">AE20121117202086</item> <item key="EOS_date">06/02/2013</item> <item key="category">I/O Module</item> <item key="count">48</item> <item key="info"><a href="https://support.netapp.com/info/communications/ECMP1110462.html " target="_blank"> CPC-0705-02 </a></item> <item key="part">ESH2 - X5511A-RC,X5511-RC-C</item> <item key="severity">8</item> </hashref> </item> </hashref> </item> <item key="options_settings"> <hashref memory_address="0x2517688"> <item key="telnet.distinct.enable"> <hashref memory_address="0x2517598"> <item key="severity">7</item> <item key="text">Option telnet.distinct.enable needs to be set to 'on' as of workaround for Bug 476803</item> </hashref> </item> </hashref> </item> </hashref> </perldata>
我倾向于认为你的计划有些不对劲.