2012-11-23 87 views
4

我試圖使用XML序列化下面的數據結構使用自卸車錯誤的散列引用::自卸車XML ::在輸出

'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:自卸車它使用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">&lt;a href=&quot;https://support.netapp.com/info/communications/ECMP1110462.html &quot; target=&quot;_blank&quot;&gt; CPC-0705-02 &lt;/a&gt;</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中的錯誤::自卸車還是我做錯了什麼?使用最新的XML :: Dumper 0.81

P.S. 我試圖在主腳本之外重現它,它工作。 我仍然無法理解主要腳本中的數據如何被破壞。 這是其中使用XML ::自卸車的代碼:

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混淆了

回答

3

我試圖在沒有任何成功的情況下複製您的問題。

#!/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, X5511-RC-C', 
    'category' => 'I/O Module', 
    'EOS_date' => '06/02/2013', 
    '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">&lt;a href=&quot;https://support.netapp.com/info/communications/ECMP1110462.html &quot; target=&quot;_blank&quot;&gt; CPC-0705-02 &lt;/a&gt;</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 &apos;on&apos; as of 
workaround for Bug 476803</item> 
    </hashref> 
    </item> 
    </hashref> 
    </item> 
</hashref> 
</perldata> 

我傾向於認爲有什麼東西掉你的程序。 :(

+0

我是更大數據結構的一部分,我會嘗試在我使用的主代碼之外重現它 – user1847362

+0

好的如果我在單獨的腳本中使用它,它可以工作:/似乎是其他代碼的問題... – user1847362

+0

@ user1847362你最終發現問題的根源嗎? – ddoxey